Well, I figured that part out earlier today. I had to rewrite it in a totally different manner and use different commands. Go go gadget proper examples!
Anyway, I've run into a new problem. This problem arises while I was trying to modularize (is that even a word?) the code I have set up because once I'm done writing everything we're going to bring it in to the main program. A piece of code I changed was:
- Code: Select all
CellStyle tableStyle = wb.createCellStyle();
Font tableFont = wb.createFont();
tableFont.setFontName("Arial");
tableFont.setFontHeightInPoints((short)12);
tableStyle.setFont(tableFont);
tableStyle.setAlignment(CellStyle.ALIGN_LEFT);
tableStyle.setBorderRight(CellStyle.BORDER_THIN);
tableStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
tableStyle.setBorderLeft(CellStyle.BORDER_THIN);
tableStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
tableStyle.setBorderTop(CellStyle.BORDER_THIN);
tableStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
tableStyle.setBorderBottom(CellStyle.BORDER_THIN);
tableStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
for(int i = 5; i < 12; i++)
{
for(int k = 6; k 8); k++)
{
Row tableRow = certSheet.getRow(i);
Cell tableCell = tableRow.getCell(k);
tableCell.setCellStyle(tableStyle);
if(dataTable[i-5][k-6] instanceof Integer)
{
tableCell.setCellValue((Integer)dataTable[i-5][k-6]);
}
else if (dataTable[i-5][k-6] instanceof String)
{
tableCell.setCellValue((String)dataTable[i-5][k-6]);
}
else if(dataTable[i-5][k-6] instanceof Double)
{
tableCell.setCellValue((Double)dataTable[i-5][k-6]);
}
}
}
which was previously residing in the method make5PtUnampCert() and it worked just fine and dandy.
I brought it out of the method, and made it it's own private method so that it now looks like:
- Code: Select all
private static void addNPointCalibTable(Sheet certSheet, Workbook wb, Object[][] dataTable)
{
CellStyle tableStyle = wb.createCellStyle();
Font tableFont = wb.createFont();
tableFont.setFontName("Arial");
tableFont.setFontHeightInPoints((short)12);
tableStyle.setFont(tableFont);
tableStyle.setAlignment(CellStyle.ALIGN_LEFT);
tableStyle.setBorderRight(CellStyle.BORDER_THIN);
tableStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
tableStyle.setBorderLeft(CellStyle.BORDER_THIN);
tableStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
tableStyle.setBorderTop(CellStyle.BORDER_THIN);
tableStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
tableStyle.setBorderBottom(CellStyle.BORDER_THIN);
tableStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
for(int i = 0; i < Array.getLength(dataTable); i++)
{
for(int k = 0; k < Array.getLength(dataTable[i]); k++)
{
Row tableRow = certSheet.getRow(i+5);
Cell tableCell = tableRow.getCell(k+6);
tableCell.setCellStyle(tableStyle); [1]
if(dataTable[i][k] instanceof Integer)
{
tableCell.setCellValue((Integer)dataTable[i][k]); [2]
}
else if (dataTable[i][k] instanceof String)
{
tableCell.setCellValue((String)dataTable[i][k]);
}
else if(dataTable[i][k] instanceof Double)
{
tableCell.setCellValue((Double)dataTable[i][k]);[3]
}
}
}
}
which errors at [1], [2], and [3] all with the same NullPointerException.
I am completely lost as to why this is happening. FWIW, the call being used in the make5PtUnampCert() method is:
- Code: Select all
addNPointCalibTable(certSheet, wb, calibDataTable);
where calibDataTable is: Object[][] calibDataTable = {{"Load", "(lbs)", 0.0, 0.0, 0.0, 0.0, 0.0,0.0},{"Output", "mV/V", 0.0, 0.0, 0.0, 0.0, 0.0,0.0}};
Lemme throw out there that if I comment out those lines which throw errors, everything compiles and runs fine, except that the calibration table is a) not outlined and b) only has the string values in it
Gigabyte Z77-DS3H | Core i7 3770 | 2x8 GB Crucial Ballistix DDR3-1600| Samsung 830 128GB SSD | Gigabyte HD7950 3GB | Win 7 Pro x86-64