日期:2014-05-20  浏览次数:21101 次

JAVA使用POI读取EXCEL错误
一讀取EXCEL就會拋出如下異常
Java code

java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:224)
        at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:160)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:163)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:210)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:191)
        at com.emis.app.pbo.dep.emisQuoteExcelToDB.quoteExcelToDb(emisQuoteExcelToDB.java:63)
        at com.emis.app.pbo.dep.emisQuoteExcelToDB.<init>(emisQuoteExcelToDB.java:47)
        at _jsp._dep._bestdaybp_0upload_0xls__jsp._jspService(_bestdaybp_0upload_0xls__jsp.java:96)
        at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
        at com.caucho.jsp.Page.subservice(Page.java:506)
        at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
        at com.caucho.server.http.Invocation.service(Invocation.java:315)
        at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
        at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:246)
        at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:164)
        at com.caucho.server.TcpConnection.run(TcpConnection.java:139)
        at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.ArrayIndexOutOfBoundsException
        at java.lang.System.arraycopy(Native Method)
        at org.apache.poi.hssf.record.UnknownRecord.<init>(UnknownRecord.java:62)
        at org.apache.poi.hssf.record.SubRecord.createSubRecord(SubRecord.java:57)
        at org.apache.poi.hssf.record.ObjRecord.fillFields(ObjRecord.java:99)
        at org.apache.poi.hssf.record.Record.fillFields(Record.java:90)
        at org.apache.poi.hssf.record.Record.<init>(Record.java:55)
        at org.apache.poi.hssf.record.ObjRecord.<init>(ObjRecord.java:61)
        ... 21 more


經過調試是 HSSFWorkbook hssfWorkbook = new HSSFWorkbook(inStream);錯誤,請大神幫助

------解决方案--------------------
java.lang.ArrayIndexOutOfBoundsException
数组下标越界。
emisQuoteExcelToDB.java:63行,
大概是数组拷贝时候数组没有开到足够大。
------解决方案--------------------
探讨

引用:

引用:

引用:

引用:

引用:

引用:

引用:

java.lang.ArrayIndex……

------解决方案--------------------
探讨
引用:

你直接写另外写个测试,就写这一句,把你那路径创建inputStream试试,那句走不通,个人觉得有可能是excel文件或者其内容的原因吧。

創建inputStream 這個能走通。。就是new HSSFWorkbook的時候就拋出異常了