我正在创建没有任何第三方应用程序读取微软文件的Android应用程序,我使用了Apache POI库。对于阅读/打开办公室文件,我能够打开doc,ppt和xls文件,但无法打开DOCx,PPTx,XLSx,我曾尝试过以下代码阅读
FileInputStream inputStream = new FileInputStream(new File(getIntent().getStringExtra(Constants.FILEPATH)));
// getResources().getAssets().open("doc2.doc");
XWPFDocument xwpfDocument = new XWPFDocument(inputStream);
xwpfDocument.getXWPFDocument();
xwpfDocument.getBodyElements();
它会抛出异常,如下所示
04-08 05:34:20.407: E/AndroidRuntime(1222): FATAL EXCEPTION: main
04-08 05:34:20.407: E/AndroidRuntime(1222): java.lang.ExceptionInInitializerError
04-08 05:34:20.407: E/AndroidRuntime(1222): at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:154)
04-08 05:34:20.407: E/AndroidRuntime(1222): at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:141)
04-08 05:34:20.407: E/AndroidRuntime(1222): at org.apache.poi.openxml4j.opc.Package.<init>(Package.java:37)
04-08 05:34:20.407: E/AndroidRuntime(1222): at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:83)
04-08 05:34:20.407: E/AndroidRuntime(1222): at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:272)
04-08 05:34:20.407: E/AndroidRuntime(1222): at org.apache.poi.util.PackageHelper.open(PackageHelper.java:39)
04-08 05:34:20.407: E/AndroidRuntime(1222): at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:121)
04-08 05:34:20.407: E/AndroidRuntime(1222): at com.narola.yujidownloader.OfficeActivity.populateWordX(OfficeActivity.java:605)
04-08 05:34:20.407: E/AndroidRuntime(1222): at com.narola.yujidownloader.OfficeActivity.populate(OfficeActivity.java:139)
04-08 05:34:20.407: E/AndroidRuntime(1222): at com.narola.yujidownloader.OfficeActivity.initialize(OfficeActivity.java:111)
04-08 05:34:20.407: E/AndroidRuntime(1222): at com.narola.yujidownloader.OfficeActivity.onCreate(OfficeActivity.java:96)
04-08 05:34:20.407: E/AndroidRuntime(1222): at android.app.Activity.performCreate(Activity.java:5008)
04-08 05:34:20.407: E/AndroidRuntime(1222): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
04-08 05:34:20.407: E/AndroidRuntime(1222): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
04-08 05:34:20.407: E/AndroidRuntime(1222): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
04-08 05:34:20.407: E/AndroidRuntime(1222): at android.app.ActivityThread.access$600(ActivityThread.java:130)
04-08 05:34:20.407: E/AndroidRuntime(1222): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
04-08 05:34:20.407: E/AndroidRuntime(1222): at android.os.Handler.dispatchMessage(Handler.java:99)
04-08 05:34:20.407: E/AndroidRuntime(1222): at android.os.Looper.loop(Looper.java:137)
04-08 05:34:20.407: E/AndroidRuntime(1222): at android.app.ActivityThread.main(ActivityThread.java:4745)
04-08 05:34:20.407: E/AndroidRuntime(1222): at java.lang.reflect.Method.invokeNative(Native Method)
04-08 05:34:20.407: E/AndroidRuntime(1222): at java.lang.reflect.Method.invoke(Method.java:511)
04-08 05:34:20.407: E/AndroidRuntime(1222): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-08 05:34:20.407: E/AndroidRuntime(1222): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-08 05:34:20.407: E/AndroidRuntime(1222): at dalvik.system.NativeStart.main(Native Method)
04-08 05:34:20.407: E/AndroidRuntime(1222): Caused by: java.lang.NoClassDefFoundError: org.dom4j.Namespace
04-08 05:34:20.407: E/AndroidRuntime(1222): at org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller.<clinit>(PackagePropertiesUnmarshaller.java:49)
我已提到Apchae POI docx
请指导我