我正在使用java2word库在Android中创建Word文档。它工作正常,但是当我尝试将图像添加到文档时,它会因以下错误而崩溃。为什么我会收到此错误,我该如何解决?
这是我的代码:
private void saveFile() {
IDocument myDoc = new Document2004();
myDoc.encoding(Encoding.UTF_8);
myDoc.setPageOrientationLandscape();
myDoc.addEle(Image.from_WEB_URL(
"http://www.google.com/images/logos/ps_logo2.png"));
myDoc.addEle(Heading1.with("Document Create Test : " + firstName + " " +
lastName +".").create();
myDoc.addEle(BreakLine.times(1).create()); //two break lines
String myWord = myDoc.getContent();
File fileObj = new File("file:///android_asset/mydocument.doc");
PrintWriter writer = null;
try {
writer = new PrintWriter(fileObj );
} catch (FileNotFoundException e) {
e.printStackTrace();
}
writer.println(myDoc.getContent());
writer.close();
}
当我执行上面的代码时,我收到以下错误:
05-12 23:46:20.693: E/AndroidRuntime(7093): FATAL EXCEPTION: main
05-12 23:46:20.693: E/AndroidRuntime(7093): java.lang.NoClassDefFoundError: javax.imageio.ImageIO
05-12 23:46:20.693: E/AndroidRuntime(7093): at word.w2004.elements.Image.<init>(Image.java:40)
05-12 23:46:20.693: E/AndroidRuntime(7093): at word.w2004.elements.Image.from_WEB_URL(Image.java:162)
05-12 23:46:20.693: E/AndroidRuntime(7093): at com.paysheet.SignatureAcitivity.saveFile(MyTestActivity.java:164)
05-12 23:46:20.693: E/AndroidRuntime(7093): at com.paysheet.SignatureAcitivity.save(MyTestActivity.java:99)
05-12 23:46:20.693: E/AndroidRuntime(7093): at com.paysheet.SignatureAcitivity$1.onClick(MyTestActivity.java:77)
05-12 23:46:20.693: E/AndroidRuntime(7093): at android.view.View.performClick(View.java:3517)
05-12 23:46:20.693: E/AndroidRuntime(7093): at android.view.View$PerformClick.run(View.java:14155)
05-12 23:46:20.693: E/AndroidRuntime(7093): at android.os.Handler.handleCallback(Handler.java:605)
答案 0 :(得分:2)
您需要让xstream库能够使用java2word处理图像。您可以从这里获取图书馆:https://code.google.com/p/java2word/downloads/detail?name=xstream-1.3.1.jar&can=2&q=