0
votes

I am trying to create a simple .docx file using Apache POI-ooxml jar file. When I add the jar, all looks well and Eclipse doesn't complain of any error. But when I run the app, apps crashes saying:

02-19 11:05:36.555: E/AndroidRuntime(17223): java.lang.VerifyError: org/apache/poi/xwpf/usermodel/XWPFDocument
02-19 11:05:36.555: E/AndroidRuntime(17223):    at com.example.filegenerator.MainActivity$2.onClick(MainActivity.java:177)
02-19 11:05:36.555: E/AndroidRuntime(17223):    at android.view.View.performClick(View.java:4101)   
02-19 11:05:36.555: E/AndroidRuntime(17223):    at android.view.View$PerformClick.run(View.java:17088)
02-19 11:05:36.555: E/AndroidRuntime(17223):    at android.os.Handler.handleCallback(Handler.java:615)
02-19 11:05:36.555: E/AndroidRuntime(17223):    at android.os.Handler.dispatchMessage(Handler.java:92)
02-19 11:05:36.555: E/AndroidRuntime(17223):    at android.os.Looper.loop(Looper.java:153)
02-19 11:05:36.555: E/AndroidRuntime(17223):    at android.app.ActivityThread.main(ActivityThread.java:5096)
02-19 11:05:36.555: E/AndroidRuntime(17223):    at java.lang.reflect.Method.invokeNative(Native Method)
02-19 11:05:36.555: E/AndroidRuntime(17223):    at java.lang.reflect.Method.invoke(Method.java:511)
02-19 11:05:36.555: E/AndroidRuntime(17223):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
02-19 11:05:36.555: E/AndroidRuntime(17223):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
02-19 11:05:36.555: E/AndroidRuntime(17223):    at   dalvik.system.NativeStart.main(Native Method)

and my code for .docx file creation is :

XWPFDocument document = new XWPFDocument();
XWPFParagraph tmpParagraph = document.createParagraph();
XWPFRun tmpRun = tmpParagraph.createRun();
tmpRun.setText("LALALALAALALAAAA");
tmpRun.setFontSize(18);
try {
document.write(new FileOutputStream(new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/testfiles/"+"testfile"+extension)));
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Note: Line 177 corresponds to

 XWPFDocument document = new XWPFDocument();

in my code above.

How do I overcome this? I am using the jar file poi-ooxml-3.5-FINAL for this.

Edit: Can someone please suggest which exact jar file I am to use for generating .docx files? Please provide a link for the same.

Are you perhaps missing a dependency jar? There's a full list of the dependencies on the Apache POI website, which you can use to look up which ones you need for XWPFGagravarr
I have added all necessary dependencies. Please check here for details. stackoverflow.com/questions/21877532/…SoulRayder
Are you sure you've added them in a way that Android likes? Android isn't a full Java implementation, and does lots of things differently, so you'll need to ensure you've done it the "Android way" rather than the Java way. (Not sure what that is, but it looks like you haven't done it....)Gagravarr
I have added them in the normal way I add external jars for any Android project. I had worked with Apache POI in the past for generating .xls files. So I thought this would be a cakewalk, but apparently its not :(SoulRayder