我在Android項目中閱讀包含POI的XLS文件時遇到了問題。讀取文件我已經做到了這一點:在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項目中。
我已經添加了這個jar在project-> properties-> Javabuild path->添加外部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}。
謝謝。