2015-06-28 72 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); 
}