gpt4 book ai didi

android - 在android中使用docx4j读取word doc时遇到如下问题

转载 作者:行者123 更新时间:2023-11-29 00:37:08 24 4
gpt4 key购买 nike

目的:将word文档内容读入控制台

使用环境:Windows 7 32bit Eclipse 集成开发环境靛蓝 安卓 4.1 API 16 Java 1.6库:docx4j-2.8.0

以下是我用来在控​​制台上打印 word doc 文本的代码 fragment

WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(Environment.getExternalStorageDirectory().getAbsolutePath(), selectedFromList));

MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
System.out.println("file contents --->>>>>" +documentPart.getContent());

DocPropsCorePart docPropsCorePart = wordMLPackage.getDocPropsCorePart();
CoreProperties coreProps = (CoreProperties)docPropsCorePart.getJaxbElement();

System.out.println("'dc:title' is " + coreProps.getTitle().getValue().getContent().get(0));
System.out.println(coreProps.getTitle().getValue().getClass().getName() );
System.out.println("'dcterms:created' is " + coreProps.getCreated().getClass().getName() );

当我尝试执行上面的代码时,我遇到了以下问题eclipse logcat 显示以下日志

08-10 12:22:37.853: I/dalvikvm(1761): Could not find method javax.xml.bind.JAXBContext.createMarshaller, referenced from method 

org.docx4j.openpackaging.packages.WordprocessingMLPackage.save
08-10 12:22:37.853: W/dalvikvm(1761): VFY: unable to resolve virtual method 7579: Ljavax/xml/bind/JAXBContext;.createMarshaller ()Ljavax/xml/bind/Marshaller;
08-10 12:22:37.853: D/dalvikvm(1761): VFY: replacing opcode 0x6e at 0x0017

08-10 12:22:37.863: I/dalvikvm(1761): Could not find method javax.xml.bind.JAXBContext.createMarshaller, referenced from method

org.docx4j.openpackaging.packages.WordprocessingMLPackage.transform

08-10 12:22:37.863: W/dalvikvm(1761): VFY: unable to resolve virtual method 7579: Ljavax/xml/bind/JAXBContext;.createMarshaller ()Ljavax/xml/bind/Marshaller;
08-10 12:22:37.863: D/dalvikvm(1761): VFY: replacing opcode 0x6e at 0x000d

08-10 12:22:37.863: I/dalvikvm(1761): Failed resolving Lorg/docx4j/jaxb/JaxbValidationEventHandler; interface 1254 'Ljavax/xml/bind/ValidationEventHandler;'
08-10 12:22:37.863: W/dalvikvm(1761): Link of class 'Lorg/docx4j/jaxb/JaxbValidationEventHandler;' failed

08-10 12:22:37.873: D/dalvikvm(1761): DexOpt: unable to opt direct call 0x46db at 0x1e in Lorg/docx4j/openpackaging/packages/WordprocessingMLPackage;.transform
08-10 12:22:37.873: D/dalvikvm(1761): DexOpt: unable to opt direct call 0x1dba at 0x26 in Lorg/docx4j/openpackaging/packages/WordprocessingMLPackage;.transform

08-10 12:22:37.883: E/dalvikvm(1761): Could not find class 'org.apache.poi.poifs.filesystem.POIFSFileSystem', referenced from method

org.docx4j.openpackaging.packages.OpcPackage.load

08-10 12:22:37.883: W/dalvikvm(1761): VFY: unable to resolve new-instance 1658 (Lorg/apache/poi/poifs/filesystem/POIFSFileSystem;) in

Lorg/docx4j/openpackaging/packages/OpcPackage;
08-10 12:22:37.883: D/dalvikvm(1761): VFY: replacing opcode 0x22 at 0x001a

08-10 12:22:37.893: I/dalvikvm(1761): Could not find method javax.xml.bind.JAXBContext.createUnmarshaller, referenced from method

org.docx4j.openpackaging.packages.OpcPackage.load

08-10 12:22:37.893: W/dalvikvm(1761): VFY: unable to resolve virtual method 7580: Ljavax/xml/bind/JAXBContext;.createUnmarshaller ()Ljavax/xml/bind/Unmarshaller;
08-10 12:22:37.893: D/dalvikvm(1761): VFY: replacing opcode 0x6e at 0x004d

08-10 12:22:37.893: I/dalvikvm(1761): Could not find method javax.xml.bind.JAXBContext.createMarshaller, referenced from method

org.docx4j.openpackaging.packages.OpcPackage.save

08-10 12:22:37.893: W/dalvikvm(1761): VFY: unable to resolve virtual method 7579: Ljavax/xml/bind/JAXBContext;.createMarshaller ()Ljavax/xml/bind/Marshaller;
08-10 12:22:37.893: D/dalvikvm(1761): VFY: replacing opcode 0x6e at 0x0017

08-10 12:22:37.905: D/dalvikvm(1761): DexOpt: unable to opt direct call 0x2654 at 0x1c in Lorg/docx4j/openpackaging/packages/OpcPackage;.load
08-10 12:22:37.905: D/dalvikvm(1761): DexOpt: unable to opt direct call 0x2651 at 0x21 in Lorg/docx4j/openpackaging/packages/OpcPackage;.load

08-10 12:22:37.905: I/dalvikvm(1761): Failed resolving Lorg/docx4j/jaxb/JaxbValidationEventHandler; interface 1254 'Ljavax/xml/bind/ValidationEventHandler;'
08-10 12:22:37.905: W/dalvikvm(1761): Link of class 'Lorg/docx4j/jaxb/JaxbValidationEventHandler;' failed

08-10 12:22:37.905: D/dalvikvm(1761): DexOpt: unable to opt direct call 0x46db at 0x53 in Lorg/docx4j/openpackaging/packages/OpcPackage;.load
08-10 12:22:37.963: W/System.err(1761): org.docx4j.openpackaging.exceptions.Docx4JException: Error reading from the stream

08-10 12:22:37.963: W/System.err(1761): at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:239)
08-10 12:22:37.963: W/System.err(1761): at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:195)
08-10 12:22:37.963: W/System.err(1761): at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:178)
08-10 12:22:37.963: W/System.err(1761): at org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:172)
08-10 12:22:37.975: W/System.err(1761): at com.reader.MainActivity$2.onItemClick(MainActivity.java:125)
08-10 12:22:37.975: W/System.err(1761): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
08-10 12:22:37.975: W/System.err(1761): at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
08-10 12:22:37.975: W/System.err(1761): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2855)
08-10 12:22:37.975: W/System.err(1761): at android.widget.AbsListView$1.run(AbsListView.java:3529)
08-10 12:22:37.984: W/System.err(1761): at android.os.Handler.handleCallback(Handler.java:615)
08-10 12:22:37.984: W/System.err(1761): at android.os.Handler.dispatchMessage(Handler.java:92)
08-10 12:22:37.984: W/System.err(1761): at android.os.Looper.loop(Looper.java:137)
08-10 12:22:37.984: W/System.err(1761): at android.app.ActivityThread.main(ActivityThread.java:4745)
08-10 12:22:37.984: W/System.err(1761): at java.lang.reflect.Method.invokeNative(Native Method)
08-10 12:22:37.993: W/System.err(1761): at java.lang.reflect.Method.invoke(Method.java:511)
08-10 12:22:37.993: W/System.err(1761): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-10 12:22:37.993: W/System.err(1761): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-10 12:22:37.993: W/System.err(1761): at dalvik.system.NativeStart.main(Native Method)
08-10 12:22:38.085: W/System.err(1761): Caused by: java.io.IOException: Mark has been invalidated.
08-10 12:22:38.085: W/System.err(1761): at java.io.BufferedInputStream.reset(BufferedInputStream.java:350)
08-10 12:22:38.093: W/System.err(1761): at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:237)

08-10 12:22:38.923: I/Choreographer(1761): Skipped 107 frames! The application may be doing too much work on its main thread.

最佳答案

披露:我从事 docx4j 项目

您需要使用 Android-specific branch of docx4j .

参见 jaxb-can-be-made-to-run-on-android

我建议你得到 AndroidDocxToHtml先工作,然后再继续。

关于android - 在android中使用docx4j读取word doc时遇到如下问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11897537/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com