我是一個工程系學生(第三年結束)做一個實習,我必須簡化創建詞彙報告(.docx)的過程。我決定開發一款Android應用程序,以便通過手機和平板電腦完成工作。需要幫助找到一個解決方案,以實現Android下的單詞報告(實際上使用docx4j)
我已經實現了在Eclipse下創建Java程序,該程序使用docx4j完全正常工作。
我完全不熟悉Android Studio(或者Eclipse插件,我都有),通過Android創建.docx的事實並不常見。 該程序分爲幾個步驟,包括導入一個.docx模板,然後分析其填充(通過MergeFields)以及其保存。這些步驟都失敗了。
這是用來導入模板的方法:
private WordprocessingMLPackage getTemplate(String name) throws Docx4JException, FileNotFoundException {
WordprocessingMLPackage template = WordprocessingMLPackage.load(new FileInputStream(new File(name)));
return template;
}
用來取代MERGEFIELDS該方法是很長,但我的主要問題是JAXBElements沒有Android Studio中進行管理。
private static List<Object> getAllElementFromObject(Object obj,
Class<?> toSearch) {
List<Object> result = new ArrayList<Object>();
if (obj instanceof JAXBElement)
obj = ((JAXBElement<?>) obj).getValue();
//end of code here
}
最後這個是用來保存完成的報表方法:
private void writeDocxToStream(WordprocessingMLPackage template,
String target) throws IOException, Docx4JException {
File f = new File(target);
template.save(f);
}
試圖相當的一切我可能做(與我的新手級^ _ ^)之後,我相信,這些有三種方法失敗,但我唯一知道原因的方法是第二種方法,使用JAXBElements。對於第一種和最後一種方法,我真的不知道要尋找什麼。
AVD應用程序不會崩潰,但在我的桌面上沒有生成文件(即使我沒有替換方法執行)。 我在logcat中返回這些消息:
07-21 14:34:18.955 2326-2326/com.example.stoneedge.vgp01 W/System.err﹕ java.io.FileNotFoundException: C:\Users\Stone Edge\Desktop\VGP Pelle.docx: open failed: ENOENT (No such file or directory)
07-21 14:34:18.955 2326-2326/com.example.stoneedge.vgp01 W/System.err﹕ at libcore.io.IoBridge.open(IoBridge.java:456)
07-21 14:34:18.955 2326-2326/com.example.stoneedge.vgp01 W/System.err﹕ at java.io.FileInputStream.<init>(FileInputStream.java:76)
07-21 14:34:18.955 2326-2326/com.example.stoneedge.vgp01 W/System.err﹕ at com.example.stoneedge.vgp01.Tracto.getTemplate(Tracto.java:123)
07-21 14:34:18.955 2326-2326/com.example.stoneedge.vgp01 W/System.err﹕ at com.example.stoneedge.vgp01.Tracto.access$000(Tracto.java:25)
07-21 14:34:18.955 2326-2326/com.example.stoneedge.vgp01 W/System.err﹕ at com.example.stoneedge.vgp01.Tracto$1.onClick(Tracto.java:44)
07-21 14:34:18.955 2326-2326/com.example.stoneedge.vgp01 W/System.err﹕ at android.view.View.performClick(View.java:4780)
07-21 14:34:18.955 2326-2326/com.example.stoneedge.vgp01 W/System.err﹕ at android.view.View$PerformClick.run(View.java:19866)
07-21 14:34:18.955 2326-2326/com.example.stoneedge.vgp01 W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:739)
07-21 14:34:18.955 2326-2326/com.example.stoneedge.vgp01 W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
07-21 14:34:18.956 2326-2326/com.example.stoneedge.vgp01 W/System.err﹕ at android.os.Looper.loop(Looper.java:135)
07-21 14:34:18.956 2326-2326/com.example.stoneedge.vgp01 W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5257)
07-21 14:34:18.956 2326-2326/com.example.stoneedge.vgp01 W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
07-21 14:34:18.956 2326-2326/com.example.stoneedge.vgp01 W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
07-21 14:34:18.956 2326-2326/com.example.stoneedge.vgp01 W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
07-21 14:34:18.956 2326-2326/com.example.stoneedge.vgp01 W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
07-21 14:34:18.956 2326-2326/com.example.stoneedge.vgp01 W/System.err﹕ Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
07-21 14:34:18.956 2326-2326/com.example.stoneedge.vgp01 W/System.err﹕ at libcore.io.Posix.open(Native Method)
07-21 14:34:18.956 2326-2326/com.example.stoneedge.vgp01 W/System.err﹕ at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
07-21 14:34:18.956 2326-2326/com.example.stoneedge.vgp01 W/System.err﹕ at libcore.io.IoBridge.open(IoBridge.java:442)
07-21 14:34:18.956 2326-2326/com.example.stoneedge.vgp01 W/System.err﹕ ... 14 more
07-21 14:34:19.008 2326-2338/com.example.stoneedge.vgp01 I/art﹕ Background partial concurrent mark sweep GC freed 1090(56KB) AllocSpace objects, 0(0B) LOS objects, 39% free, 2MB/3MB, paused 5.574ms total 67.675ms
我知道有一個尋路錯誤,但我驗證的路徑和檢查在論壇上,我找不到我怎麼可能使它工作。我曾經想過直接在設備上使用設備的路徑導入和生成.docx,但我沒有Android設備,因此也沒有考慮如何訪問這些路徑。
如果你們中的任何人都可以提供幫助,那會很棒。如果您需要更多信息或測試等,我會每天在論壇上多次查看答案。
提前,謝謝。
編輯
我想我已經放棄了這個念頭要經過的Android這個項目,我越來越充滿「」超過一千行的logcat的錯誤,我什至不能找出這個錯誤是什麼...我會嘗試找到一種方法來讓.jar應用程序在android上運行。
事情是我終於明白這一點,通過Assets重新編寫我的代碼,但是後來我得到了這些完整的「 」錯誤行,它們沒有告訴我任何東西,所以我想我會找到另一種解決方案來讓我的事情發揮作用(所以不要使用Android Studio)。非常感謝,我檢查了你的鏈接,它幫助我理解我的第一個錯誤是什麼:) –