青睞的朋友,這裏是她的查詢:NullPointerException異常的ZK API的Range.insert生成Excel文件(JExcel/Apache的POI)
Hi! I am currently using jexcelapi to create excel files and then I read them using zk spreadsheet. I tried the code found in the documentation for inserting columns and shifting cells to the right but unfortunately, a null pointer exception shows up whenever I try to insert/shift cells. I also tried uploading the excel files I created using jexcelapi to the zssapp (just to be sure) but a null pointer also shows up. But when I try to read excel files created by MS Excel, it works fine. Has anyone encountered this problem before? Any help would greatly be appreciated. PS: I also tried using POI to create files. I also encounter a null pointer exception.
以下是錯誤:
java.lang.NullPointerException
at org.zkoss.poi.hssf.record.XFExtRecord.cloneXFExtFrom(XFExtRecord.java:91)
at org.zkoss.poi.hssf.usermodel.HSSFCellStyle.cloneStyleFrom(HSSFCellStyle.java:835)
at org.zkoss.poi.hssf.usermodel.HSSFCellStyle.cloneStyleFrom(HSSFCellStyle.java:825)
at org.zkoss.zss.model.impl.BookHelper.copyFromStyleExceptBorder(BookHelper.java:3308)
at org.zkoss.zss.model.impl.HSSFSheetImpl.shiftColumnsRange(HSSFSheetImpl.java:601)
at org.zkoss.zss.model.impl.BookHelper.insertHSSFRange(BookHelper.java:1942)
at org.zkoss.zss.model.impl.BookHelper.insertRange(BookHelper.java:1931)
at org.zkoss.zss.model.impl.RangeImpl.insert(RangeImpl.java:649)
at data.InitWindow.onClick$shiftCellRight(InitWindow.java:102)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.zkoss.zk.ui.event.GenericEventListener.onEvent(GenericEventListener.java:81)
at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:192)
at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:138)
at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:305)
at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:328)
at org.zkoss.zk.ui.AbstractComponent$ForwardListener.onEvent(AbstractComponent.java:3022)
at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:192)
at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:138)
at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1603)
at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1387)
at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1107)
at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:563)
at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:457)
at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:465)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
And here is the code I use to create files. What I do here is create an excel file whenever a form is created:
public void createExcel(Integer formID, String loc){
try {
File path = new File(loc);
if (!path.exists()) {
boolean status = path.mkdirs();
}
String filename = loc + formID +".xls";
WorkbookSettings ws = new WorkbookSettings();
ws.setLocale(new Locale("en", "EN"));
WritableWorkbook workbook;
workbook = Workbook.createWorkbook(new File(filename), ws);
workbook.createSheet("Sheet1", 0);
workbook.write();
workbook.close();
} catch (IOException e) {
e.printStackTrace();
} catch (WriteException e) {
e.printStackTrace();
}
}
從我發現,她使用gwt框架作爲使用zk類的橋樑。
此查詢的原始帖子可以在這裏找到:http://www.zkoss.org/forum/listComment/15683
非常感謝你們!
這個異常有**的根本原因**嗎? – 2011-03-28 16:48:40
你有機會嘗試使用Apache POI 3.8 beta 1,然後發佈堆棧跟蹤? (我不認爲你應該得到一個,但我需要看到特定的POI能夠幫助那裏) – Gagravarr 2011-04-03 18:08:30