我正在尝试在Android中生成PDF / Docx。
我尝试了很多库:apache poi,docx4j和pdf box但是在控制台中总是有这个消息。
有什么想法吗?
例如,对于docx4j的示例代码:
-runproperties: org.osgi.framework.system.packages.extra = com.sun.net.httpserver
日志:
public class ExportNotebookToWordTask extends RoboAsyncTask<Void> {
private ProgressDialog exportProgress;
private Activity activity;
protected ExportNotebookToWordTask (Context context, Activity activity) {
super(context);
this.activity = activity;
exportProgress = new ProgressDialog(activity);
exportProgress.setIndeterminate(true);
exportProgress.setCancelable(false);
exportProgress.setCanceledOnTouchOutside(false);
exportProgress.setMessage(context.getString(R.string.export_notebook_to_pdf_progress));
}
@Override
protected void onPreExecute() throws Exception {
super.onPreExecute();
exportProgress.show();
}
@Override
public Void call() throws Exception {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
wordMLPackage.getMainDocumentPart().addParagraphOfText("Hello Word!");
File notebookDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + Constants.NOTEBOOKS_DIR);
if(!notebookDir.exists()) {
notebookDir.mkdir();
}
wordMLPackage.save(new File(notebookDir, course.getName() + Constants.DOCX_EXTENSION_FILE));
return null;
}
@Override
protected void onSuccess(Void result) throws Exception {
super.onSuccess(result);
DigitalNotebookActivity.this.finish();
}
@Override
protected void onFinally() throws RuntimeException {
super.onFinally();
if (exportProgress != null && exportProgress.isShowing()) {
exportProgress.dismiss();
}
}
}
答案 0 :(得分:0)
我遇到了由于未能初始化静态成员变量而导致的类似问题。
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.fff \t"); // fff is a wrong format, it should be SSS.
我猜实例化错误或依赖错误会导致这种异常。