这尤其是关于 stackoverflow 的一个新问题。我想知道如何使用 Jodconverter 库在 android 上进行文件转换。我看到很多例子和问题,但都是基于 java 的,甚至没有回答 android 的特定问题,甚至没有官方网站。虽然我确实看到所有者自己在他发布的一个 android 应用程序中使用了该库,因此可以使用 JODconverter 在 android 上进行转换。
以下代码来自官方网站的android版本:
OfficeManager officeManager = new DefaultOfficeManagerConfiguration().buildOfficeManager();
officeManager.start();
OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager);
try{
converter.convert(new File("/sdcard/tsxt.doc"), new File("/sdcard/tsx465t.docx"));
}catch(Exception e){
e.printStackTrace();
}
officeManager.stop();
我在运行时得到的崩溃的 Logcat 输出包括除 unoil 库之外的所有库(因为添加 unoil 会给我转换为 Dalvik 失败的错误):
06-28 05:28:50.086: E/AndroidRuntime(28629): FATAL EXCEPTION: main
06-28 05:28:50.086: E/AndroidRuntime(28629): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jopendocs/com.example.jopendocs.JODActivity}: java.lang.IllegalStateException: officeHome not set and could not be auto-detected
06-28 05:28:50.086: E/AndroidRuntime(28629): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2246)
06-28 05:28:50.086: E/AndroidRuntime(28629): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2296)
06-28 05:28:50.086: E/AndroidRuntime(28629): at android.app.ActivityThread.access$700(ActivityThread.java:151)
06-28 05:28:50.086: E/AndroidRuntime(28629): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
06-28 05:28:50.086: E/AndroidRuntime(28629): at android.os.Handler.dispatchMessage(Handler.java:99)
06-28 05:28:50.086: E/AndroidRuntime(28629): at android.os.Looper.loop(Looper.java:137)
06-28 05:28:50.086: E/AndroidRuntime(28629): at android.app.ActivityThread.main(ActivityThread.java:5293)
06-28 05:28:50.086: E/AndroidRuntime(28629): at java.lang.reflect.Method.invokeNative(Native Method)
06-28 05:28:50.086: E/AndroidRuntime(28629): at java.lang.reflect.Method.invoke(Method.java:511)
06-28 05:28:50.086: E/AndroidRuntime(28629): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
06-28 05:28:50.086: E/AndroidRuntime(28629): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
06-28 05:28:50.086: E/AndroidRuntime(28629): at dalvik.system.NativeStart.main(Native Method)
06-28 05:28:50.086: E/AndroidRuntime(28629): Caused by: java.lang.IllegalStateException: officeHome not set and could not be auto-detected
06-28 05:28:50.086: E/AndroidRuntime(28629): at org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration.buildOfficeManager(DefaultOfficeManagerConfiguration.java:163)
06-28 05:28:50.086: E/AndroidRuntime(28629): at com.example.jopendocs.JODActivity.onCreate(JODActivity.java:22)
06-28 05:28:50.086: E/AndroidRuntime(28629): at android.app.Activity.performCreate(Activity.java:5250)
06-28 05:28:50.086: E/AndroidRuntime(28629): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
06-28 05:28:50.086: E/AndroidRuntime(28629): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2210)
06-28 05:28:50.086: E/AndroidRuntime(28629): ... 11 more