我正在尝试解析.xlsx文件,但是我总是遇到同样的错误:
> 20762-20762/com.epon E/dalvikvm﹕ Could not find class 'org.apache.xmlbeans.XmlOptions', referenced from method org.apache.poi.xssf.usermodel.XSSFWorkbook.commit
10-21 02:09:25.792 20762-20762/com.epon E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.VerifyError: org/apache/poi/xssf/usermodel/XSSFWorkbook
at com.epon.MainActivity.MainActivity.onCreate(MainActivity.java:90)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
我的代码示例:
File file = new File(Environment.getExternalStorageDirectory()
.getAbsolutePath(), "Base.xlsx");
FileInputStream file1 = null;
try {
file1 = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Workbook workbook = null;
try {
workbook = new XSSFWorkbook(file1);
} catch (IOException e) {
e.printStackTrace();
}
我添加了罐子:
dependencies {
compile files('/libs/poi-3.9-20121203.jar')
compile files('/libs/poi-ooxml-3.9-20121203.jar')
compile files('/libs/xmlbeans-2.3.0.jar')
compile files('/libs/poi-ooxml-schemas-3.9-20121203.jar')
}
我已经在stackoverflow上阅读了所有解决方案,但它不起作用。
我正在使用Android Studio 0.3.0
答案 0 :(得分:0)
如果出现验证错误,还应仔细阅读错误本身之前的警告。它有时会指出错误发生的原因。
例如,在您的异常跟踪中,我们可以看到Dalvik无法加载类,但您似乎包含它。
阅读上面那个错误的警告,他们可能会帮助理解为什么这个类无法加载,也许它的超类缺失,或者它与某些东西发生冲突等。