Bug 62098 - exceptions while updating xlsx-file
Summary: exceptions while updating xlsx-file
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.17-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-02-12 18:31 UTC by Markus
Modified: 2018-02-13 20:51 UTC (History)
0 users



Attachments
test-File like the original (11.01 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2018-02-12 18:31 UTC, Markus
Details
my short standalone program and my xlsxFile (9.87 KB, application/x-zip-compressed)
2018-02-13 19:06 UTC, Markus
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Markus 2018-02-12 18:31:25 UTC
Created attachment 35728 [details]
test-File like the original

code that causes the bug:

	public void dateiSpeichern(){


		

		try (FileOutputStream outPutStream = new FileOutputStream(actualFile)){

	
			System.out.println("File: "+actualFile);
			System.out.println("Sheet: "+actualSheet.getSheetName());

			//Daten abspeichern
			Header header=actualSheet.getHeader();
			header.setLeft(jtaZeitraum.getText());
			header.setCenter(jtaAnschrift.getText());;
			header.setRight(jtaVonBis.getText());
			
			for(int i=0; i<datensatzListe.size(); i++){
				
				XSSFRow row=actualSheet.getRow(i+3);
				System.out.println("Row: "+row.getRowNum());
				XSSFCell cell0=row.getCell(0);
				cell0.setCellValue("");
				XSSFCell cell1=row.getCell(1);
				cell1.setCellValue("");
				XSSFCell cell2=row.getCell(2);
				cell2.setCellValue("");
				XSSFCell cell3=row.getCell(3);
				cell3.setCellValue("");
				XSSFCell cell4=row.getCell(4);
				cell4.setCellValue("");
				XSSFCell cell5=row.getCell(5);
				cell5.setCellValue("");
				XSSFCell cell6=row.getCell(6);
				cell6.setCellValue("");
				XSSFCell cell7=row.getCell(7);
				cell7.setCellValue("");
				XSSFCell cell8=row.getCell(8);
				cell8.setCellValue("");
				XSSFCell cell9=row.getCell(9);
				cell9.setCellValue("");
				XSSFCell cell10=row.getCell(10);
				cell10.setCellValue("");
			}
			for(int i=0; i<datensatzListe.size(); i++){
				
				XSSFRow row=actualSheet.getRow(i+3);
				System.out.println("Row: "+row.getRowNum());
				XSSFCell cell0=row.getCell(0);
				System.out.println("Cell: "+cell0.getColumnIndex());
				cell0.setCellValue(datensatzListe.get(i).getEinnahmen());
				XSSFCell cell1=row.getCell(1);
				cell1.setCellValue(datensatzListe.get(i).getMwstEin());
				XSSFCell cell2=row.getCell(2);
				cell2.setCellValue(datensatzListe.get(i).getAusgaben());
				XSSFCell cell3=row.getCell(3);
				cell3.setCellValue(datensatzListe.get(i).getMwst19Aus());
				XSSFCell cell4=row.getCell(4);
				cell4.setCellValue(datensatzListe.get(i).getMwst7Aus());
				XSSFCell cell5=row.getCell(5);
				cell5.setCellValue(datensatzListe.get(i).getRechnr());
				XSSFCell cell6=row.getCell(6);
				cell6.setCellValue(datensatzListe.get(i).getZaehler());
				XSSFCell cell7=row.getCell(7);
				cell7.setCellValue(datensatzListe.get(i).getDate());
				XSSFCell cell8=row.getCell(8);
				cell8.setCellValue(datensatzListe.get(i).getVonFuer());
				XSSFCell cell9=row.getCell(9);
				cell9.setCellValue(datensatzListe.get(i).getRubrik());
				XSSFCell cell10=row.getCell(10);
				cell10.setCellValue(datensatzListe.get(i).getKonto());
				
			}
			
			tabelleAktualisieren();
			
			


			
			
			actualWB.write(outPutStream);
			outPutStream.flush();
			outPutStream.close();
			writerEx.flushFileWriter();

		
	} catch (IOException e) {
		e.printStackTrace();
		writerEx.printIOException(e);

	} catch (NullPointerException e1) {
		e1.printStackTrace();
		writerEx.printNullPointerException(e1);

	} catch (Exception e2) {
		e2.printStackTrace();
		writerEx.printException(e2);

	}finally{
		
	}
	

	}

The exception: 

java.lang.NullPointerException
	at gui.Reiter.dateiSpeichern(Reiter.java:576)
	at gui.Hauptfenster$4.actionPerformed(Hauptfenster.java:405)
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
	at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
	at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833)
	at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:877)
	at java.awt.Component.processMouseEvent(Component.java:6533)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
	at java.awt.Component.processEvent(Component.java:6298)
	at java.awt.Container.processEvent(Container.java:2236)
	at java.awt.Component.dispatchEventImpl(Component.java:4889)
	at java.awt.Container.dispatchEventImpl(Container.java:2294)
	at java.awt.Component.dispatchEvent(Component.java:4711)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
	at java.awt.Container.dispatchEventImpl(Container.java:2280)
	at java.awt.Window.dispatchEventImpl(Window.java:2746)
	at java.awt.Component.dispatchEvent(Component.java:4711)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
	at java.awt.EventQueue.access$500(EventQueue.java:97)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.awt.EventQueue$3.run(EventQueue.java:703)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
	at java.awt.EventQueue$4.run(EventQueue.java:731)
	at java.awt.EventQueue$4.run(EventQueue.java:729)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)


Thanks for checking this problem!

Best Regards Markus
Comment 1 Nick Burch 2018-02-12 18:46:53 UTC
There doesn't seem to be any Apache POI code involved in your stacktrace. Therefore, it rather seems to be a bug in your code...

Can you write a short junit unit test case (or similar standalone program) which shows the issue to be in POI?
Comment 2 Markus 2018-02-13 19:06:15 UTC
Created attachment 35730 [details]
my short standalone program and my xlsxFile

Hi,

with this short JavaFile with the code I got the following exception:

java.lang.NullPointerException
	at gui.WriteWorkbook.write(WriteWorkbook.java:42)
	at gui.WriteWorkbook.<init>(WriteWorkbook.java:22)
	at gui.WriteWorkbook.main(WriteWorkbook.java:113)

Best regards

Markus
Comment 3 PJ Fanning 2018-02-13 19:20:28 UTC
Markus - the NullPointerException is in your code, not in Apache POI.

Line 42 in your code is
cell0=row.getCell(0);

So most likely the row is null.

I opened the xlsx file in your zip and the sheet called `test` is empty - which might explain why getRow for that sheet is returning null.