| 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: 2341
|
|
|
Which is line 30?
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16680
|
|
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)
|
 |
 |
|
|
subject: Help Null Pointer Exception
|
|
|