I need to view an .xsl file using apache poi libraries. My .xsl files contain an empty row into the table e.g. (extract from the table) a a a a a a a a a <---- Empty row a a a a a a a a a But when I try to excecute the main method in the SViewerPanel.java with argumet the .xsl file, the application throw the following Exception : Exception in thread "main" java.lang.NullPointerException at org.apache.poi.hssf.contrib.view.SVRowHeader$RowHeaderRenderer.getListCellRender erComponent(SVRowHeader.java:77) at javax.swing.plaf.basic.BasicListUI.updateLayoutState (BasicListUI.java:1148) at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState (BasicListUI.java:1098) at javax.swing.plaf.basic.BasicListUI.getPreferredSize (BasicListUI.java:281) at javax.swing.JComponent.getPreferredSize(JComponent.java:1275) at javax.swing.JList.getPreferredScrollableViewportSize(JList.java:1913) at javax.swing.ViewportLayout.preferredLayoutSize (ViewportLayout.java:72) at java.awt.Container.preferredSize(Container.java:1178) at java.awt.Container.getPreferredSize(Container.java:1162) at javax.swing.JComponent.getPreferredSize(JComponent.java:1277) at javax.swing.ScrollPaneLayout.layoutContainer (ScrollPaneLayout.java:717) at java.awt.Container.layout(Container.java:1020) at java.awt.Container.doLayout(Container.java:1010) at java.awt.Container.validateTree(Container.java:1092) at java.awt.Container.validateTree(Container.java:1099) at java.awt.Container.validateTree(Container.java:1099) at java.awt.Container.validateTree(Container.java:1099) at java.awt.Container.validateTree(Container.java:1099) at java.awt.Container.validateTree(Container.java:1099) at java.awt.Container.validateTree(Container.java:1099) at java.awt.Container.validate(Container.java:1067) at java.awt.Window.show(Window.java:461) at java.awt.Component.show(Component.java:1133) at java.awt.Component.setVisible(Component.java:1088) at org.apache.poi.hssf.contrib.view.SViewerPanel.main (SViewerPanel.java:287) May you help me?
HSSFSheet.getRow(int) may return null if the row is missing. This call appears to be on line 76 in the latest version. I can't find a good explanation for why your stacktrace says line 77. If the NPE is really coming from 'd.height' (on line 77), then please ignore this posting. This is the current code: Dimension d = getPreferredSize(); int rowHeight = (int)sheet.getRow(index).getHeightInPoints(); d.height = rowHeight+extraHeight; I would propose this fix: Dimension d = getPreferredSize(); HSSFRow row = sheet.getRow(index); int rowHeight; if(row == null) { rowHeight = (int)sheet.getDefaultRowHeightInPoints(); } else { rowHeight = (int)row.getHeightInPoints(); } d.height = rowHeight+extraHeight;
Created attachment 21571 [details] svn diff of one changed file
(In reply to comment #1) > HSSFSheet.getRow(int) may return null if the row is missing. This call > appears to be on line 76 in the latest version. I can't find a good > explanation for why your stacktrace says line 77. If the NPE is really coming > from 'd.height' (on line 77), then please ignore this posting. > This is the current code: > Dimension d = getPreferredSize(); > int rowHeight = (int)sheet.getRow(index).getHeightInPoints(); > d.height = rowHeight+extraHeight; > I would propose this fix: > Dimension d = getPreferredSize(); > HSSFRow row = sheet.getRow(index); > int rowHeight; > if(row == null) { > rowHeight = (int)sheet.getDefaultRowHeightInPoints(); > } else { > rowHeight = (int)row.getHeightInPoints(); > } > d.height = rowHeight+extraHeight; Yes the correct row is 76, in my cut & paste I have attached the wrong StackTrace. Now I rewrite the correct StackTrace: Exception in thread "main" java.lang.NullPointerException at org.apache.poi.hssf.contrib.view.SVRowHeader$RowHeaderRenderer.getListCellRender erComponent(SVRowHeader.java:76) at javax.swing.plaf.basic.BasicListUI.updateLayoutState (BasicListUI.java:1148) at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState (BasicListUI.java:1098) at javax.swing.plaf.basic.BasicListUI.getPreferredSize (BasicListUI.java:281) at javax.swing.JComponent.getPreferredSize(JComponent.java:1275) at javax.swing.JList.getPreferredScrollableViewportSize(JList.java:1913) at javax.swing.ViewportLayout.preferredLayoutSize (ViewportLayout.java:72) at java.awt.Container.preferredSize(Container.java:1178) at java.awt.Container.getPreferredSize(Container.java:1162) at javax.swing.JComponent.getPreferredSize(JComponent.java:1277) at javax.swing.ScrollPaneLayout.layoutContainer (ScrollPaneLayout.java:717) at java.awt.Container.layout(Container.java:1020) at java.awt.Container.doLayout(Container.java:1010) at java.awt.Container.validateTree(Container.java:1092) at java.awt.Container.validateTree(Container.java:1099) at java.awt.Container.validateTree(Container.java:1099) at java.awt.Container.validateTree(Container.java:1099) at java.awt.Container.validateTree(Container.java:1099) at java.awt.Container.validateTree(Container.java:1099) at java.awt.Container.validateTree(Container.java:1099) at java.awt.Container.validate(Container.java:1067) at java.awt.Window.show(Window.java:461) at java.awt.Component.show(Component.java:1133) at java.awt.Component.setVisible(Component.java:1088) at org.apache.poi.hssf.contrib.view.SViewerPanel.main (SViewerPanel.java:287)
Created attachment 21572 [details] sreenshot of the new problem. I have made changes described in your attachment (id=21571). Now the table is correctly displayed, but there's still a little bug: the last row doesn't have a corresponding row number in the left enumeration column. I attach you a screenshot of the problem. I have some questions, due to I'm a beginnes in submit an issue into a Bugzilla system: 1) which version of libraries will have changes, when the issue will be resolved? 2) what are the formal step that I do to completed this issue? Thank you in advance.
3) In which version of the library the fix will be delivered? Can I include the fixed source code into my distribution, in respect with Apache License?
Thanks for the patch Josh, looks just the job. Applied in svn. I've also fixed the missing row numbers problem, which was caused by calling getPhysicalNumberOfRows when we meant to call getLastRowNumber. Now works fine with the version in svn. Giuseppe - fixes are ASL licensed, so you're welcome to use them under the same terms as the rest of poi. They're in svn now, will be in tonight's nightly build, and will be included in the next release
I've tried to perform changes from getPhysicalNumberOfRows to getLastRowNum() (getLastRowNumber) in SViewerPanel.java and SVRowHeader.java classes, but the bug is still present. I have also noted that the table row was eliminated into the .xls file.
Please try with a svn checkout from trunk. If the problem remains, please attach a problem excel file so we can test against that - all my sample files now work just fine.