Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help Null Pointer Exception

 
Jesse Walker
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the error I am getting and below is my code, what am I doing wrong, I cannt find anything that I am not initilazing(sp). Any help would be greatly appreciated.
Thanks,

java.lang.NullPointerException

at wirelessWriter.toExcel.<init>(toExcel.java:30)

at wirelessWriter.toExcel.main(toExcel.java:46)

Exception in thread "main"

Java Result: 1


package wirelessWriter;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.poifs.filesystem.*;
import java.io.*;
import javax.swing.*;
/**
*
* @author tech
*/
public class toExcel {
File f = new File("C:\\Workbook.xls");
POIFSFileSystem fs;

public toExcel(){
if(f.exists()){
try{
fs = new POIFSFileSystem(new FileInputStream(f));
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(2);
HSSFCell cell = row.createCell((short)0);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue("test");
FileOutputStream fileOut = new FileOutputStream(f);
wb.write(fileOut);
fileOut.close();
}
catch(FileNotFoundException fe){
fe.printStackTrace();
}catch(IOException io){
io.printStackTrace();

}
}
}
public static void main(String[] args){
new toExcel();
}
}
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which is line 30?
 
Henry Wong
author
Marshal
Pie
Posts: 20998
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any help would be greatly appreciated. Thanks,

java.lang.NullPointerException
at wirelessWriter.toExcel.<init>(toExcel.java:30)


The error is reporting the location as line 30 of the toExecl.java file. Load up the file with your editor and take a look at line 30, and probably a few lines before.

Henry
[ February 21, 2007: Message edited by: Henry Wong ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic