Creating a .docx file using poi-ooxml jar file

旧时模样 提交于 2019-12-18 09:51:45

问题


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.

来源:https://stackoverflow.com/questions/21872019/creating-a-docx-file-using-poi-ooxml-jar-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!