2015-06-28 44 views
1

这是对stackoverflow特别新的问题。我想知道如何使用Jodconverter库在android上进行文件转换。我看到很多的例子和问题,但都是基于java,而不是回答android的具体问题,甚至不是官方网站。虽然我确实看到主人自己已经在一个他发布的android应用程序中使用过该库,所以它有可能通过JODconverter在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的输出I在运行时获得包括除除油库中的所有库(因为加入除油给我转换为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 
+0

你找到任何解决方案? – SwapnilPopat

回答

1

我觉得这不可能是可能作为JODConverter需要一个有效的OpenOffice安装。 开始时,这个库试图猜测OpenOffice安装文件夹(大部分时间,根据操作系统,OpenOffice位于特定文件夹), 但Android,我不知道这是可能的。 我没有Android设备,我不知道此操作系统上是否有OpenOffice。 如果是,你必须建立officeHome attribut(看一个org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration类,如果我是正确的)

0

从官方网站的代码是不同的,从你的:

final LocalOfficeManager officeManager = LocalOfficeManager.install(); 
try { 

    // Start an office process and connect to the started instance (on port 2002). 
    officeManager.start(); 

    // Convert 
    JodConverter 
      .convert(inputFile) 
      .to(outputFile) 
      .execute(); 
} finally { 
    // Stop the office process 
    OfficeUtils.stopQuietly(officeManager); 
}