我在Android项目中使用POI读取XLS文件时遇到问题。要阅读文件我已经这样做了:
InputStream is = null;
try {
is = getInstrumentation().getContext().getAssets().open("abc.xlsx");
} catch (IOException e) {
}
这解决了阅读问题,但现在我遇到了这个代码的另一个问题:
XSSFWorkbook workbook = new XSSFWorkbook(is);
XSSFSheet sheet = workbook.getSheetAt(0);
这给了我以下错误:
java.lang.NoClassDefFoundError: org.apache.poi.xssf.usermodel.XSSFWorkbook
at com.evernote.test.Xls_Reader.<init>(Xls_Reader.java:36)
at com.evernote.test.Main.readTestCaseXls(Main.java:87)
at com.evernote.test.Main.testCreateAccount(Main.java:62)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1661)
我已经包含了所有必需的POI库,并且在Java项目中它可以正常工作。问题出在Android项目中。
我在project-&gt; properties-&gt; Javabuild path-&gt;添加外部jar中添加了这个jar。我收录了以下jar poi-scratchpad-3.9-20121203,poi-ooxml-schemas-3.9-20121203,poi-ooxml-3.9-20121203,poi-ooxml-3.9,poi-excelant-3.9-20121203,poi-examples-3.9 -20121203,poi-3.9-20121203,为了顺序和导出我没有检查poi-ooxml-schemas-3.9-20121203 jar如果我检查了它然后它给出错误{Dx麻烦编写输出:太多方法:66024;最大值为65536.按包:13 java.lang 1 java.lang.reflect}。
感谢。
答案 0 :(得分:0)
如果您确定已包含所有jar,则会出现此异常,然后在项目根目录中创建一个libs文件夹并复制libs文件夹中的所有jar。在java构建路径中添加这些jar(选择所有jar并右键单击add jars。)