Java POI ClassNotFoundException

2019-09-05 03:43发布

问题:

im trying to use the POI classes from apache to convert a dovx to txt. I included all the jars that the zip has, but i get this error:

05-21 21:32:04.508: E/dalvikvm(1977): Could not find class 'org.apache.poi.xwpf.usermodel.XWPFDocument', referenced from method com.example.flashcards.WordToTxt.convert
05-21 21:32:04.508: E/AndroidRuntime(1977): FATAL EXCEPTION: main
05-21 21:32:04.508: E/AndroidRuntime(1977): java.lang.NoClassDefFoundError: org.apache.poi.xwpf.usermodel.XWPFDocument
05-21 21:32:04.508: E/AndroidRuntime(1977):     at com.example.flashcards.WordToTxt.convert(WordToTxt.java:16)
05-21 21:32:04.508: E/AndroidRuntime(1977):     at com.example.flashcards.MainActivity.onCreate(MainActivity.java:65)
05-21 21:32:04.508: E/AndroidRuntime(1977):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-21 21:32:04.508: E/AndroidRuntime(1977):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
05-21 21:32:04.508: E/AndroidRuntime(1977):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
05-21 21:32:04.508: E/AndroidRuntime(1977):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-21 21:32:04.508: E/AndroidRuntime(1977):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
05-21 21:32:04.508: E/AndroidRuntime(1977):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-21 21:32:04.508: E/AndroidRuntime(1977):     at android.os.Looper.loop(Looper.java:130)
05-21 21:32:04.508: E/AndroidRuntime(1977):     at android.app.ActivityThread.main(ActivityThread.java:3683)
05-21 21:32:04.508: E/AndroidRuntime(1977):     at java.lang.reflect.Method.invokeNative(Native Method)
05-21 21:32:04.508: E/AndroidRuntime(1977):     at java.lang.reflect.Method.invoke(Method.java:507)
05-21 21:32:04.508: E/AndroidRuntime(1977):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-21 21:32:04.508: E/AndroidRuntime(1977):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-21 21:32:04.508: E/AndroidRuntime(1977):     at dalvik.system.NativeStart.main(Native Method)

and the jar that i included are:

poi-examples
poi-excelant
poi-ooxml
poi-scratchpad

dom4j
stax-api
xmlbeans

Why is not finding that class?? thanks a lot

Now i've these jars in dependencies (in eclipse)

26/11/2012  16:22         1.869.113 poi-3.9-20121203.jar
26/11/2012  16:22           309.368 poi-examples-3.9-20121203.jar
26/11/2012  16:22            30.446 poi-excelant-3.9-20121203.jar
26/11/2012  16:22           936.648 poi-ooxml-3.9-20121203.jar
26/11/2012  16:22         4.802.621 poi-ooxml-schemas-3.9-20121203.jar
26/11/2012  16:22         1.226.511 poi-scratchpad-3.9-20121203.jar

14/05/2011  09:51            73.098 commons-codec-1.5.jar
18/09/2009  15:17            52.915 commons-logging-1.1.jar
05/04/2009  12:24           121.070 junit-3.8.1.jar
05/04/2009  12:24           358.180 log4j-1.2.13.jar

05/04/2009  12:28           313.898 dom4j-1.6.1.jar
23/02/2011  11:31            26.514 stax-api-1.0.1.jar
05/04/2009  12:29         2.666.695 xmlbeans-2.3.0.jar

回答1:

Looks like you are missing a few jar's.

http://poi.apache.org/overview.html

You need:

poi-version-yyyymmdd.jar
commons-logging.jar
commons-codec.jar
log4j.jar
poi-ooxml-schemas-version-yyyymmdd.jar
xmlbeans.jar
stax-api-1.0.1.jar
dom4j.jar