Reputation: 1747
I am using the java2word library to create a Word document in Android. It's working fine, but when I try to add an image to the document, it crashes with the below error. Why am I getting this error, and how do I fix it?
Here's my code:
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();
}
When I execute the above code, I get the following error:
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)
Upvotes: 1
Views: 765
Reputation: 301
You need to have the xstream library to be able to handle images with java2word. You can get the library from here: https://code.google.com/p/java2word/downloads/detail?name=xstream-1.3.1.jar&can=2&q=
Upvotes: 2