File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Help Null Pointer Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help Null Pointer Exception" Watch "Help Null Pointer Exception" New topic
Author

Help Null Pointer Exception

Jesse Walker
Ranch Hand

Joined: Aug 18, 2004
Posts: 50
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

Joined: Feb 07, 2005
Posts: 2367
Which is line 30?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18507
    
  40

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 ]

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help Null Pointer Exception
 
Similar Threads
Using HSSFWorkbook to copy excel file
excel
java program for pdf file to excel file conversion
Not able to complie JSP file.
Using HSSFWorkbook to copy excel file