问题
I'm having weird trouble with Apache Batik library linked to my Android&LibGDX project.
But let's start from beginning, in IntelliJ Idea I have a project which contains three modules: Main, Android and Desktop.
"batik" library which I highlighted contains:
And there is some code in "Main" module which is used in Android&Desktop modules:
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(parser);
Following code is used to get SVG document's width and height, but calling SAXSVGDocumentFactory's constructor throws an exception only on Android. There is no problem on Desktop version which runs without any problems:
03-17 18:23:46.928: ERROR/AndroidRuntime(1517): FATAL EXCEPTION: GLThread 17
java.lang.NoClassDefFoundError: org.apache.batik.dom.svg.SVGDOMImplementation
at org.apache.batik.dom.svg.SAXSVGDocumentFactory.<init>(SAXSVGDocumentFactory.java:111)
at com.revicostudio.gra.GraRenderer.getDocumentWidthAndHeight(GraRenderer.java:103)
at com.revicostudio.gra.GraRenderer.renderSvgToTexture(GraRenderer.java:66)
at com.revicostudio.gra.GraRenderer.render(GraRenderer.java:59)
at com.revicostudio.gra.GraScreen.render(GraScreen.java:31)
at com.badlogic.gdx.Game.render(Game.java:46)
at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:499)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1462)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)
There are also a lot of messages in Logcat send by dalvik and related to org.apache.batik.dom.* classes, which as far as I see are included in batik-svg-dom.jar:
03-17 20:26:37.688: INFO/dalvikvm(3632): Failed resolving Lorg/apache/batik/dom/ExtensibleDOMImplementation; interface 5043 'Lorg/w3c/dom/css/DOMImplementationCSS;'
03-17 20:26:37.688: WARN/dalvikvm(3632): Link of class 'Lorg/apache/batik/dom/ExtensibleDOMImplementation;' failed
03-17 20:26:37.688: WARN/dalvikvm(3632): Unable to resolve superclass of Lorg/apache/batik/dom/svg/SVGDOMImplementation; (2490)
03-17 20:26:37.688: WARN/dalvikvm(3632): Link of class 'Lorg/apache/batik/dom/svg/SVGDOMImplementation;' failed
03-17 20:26:37.688: INFO/dalvikvm(3632): Could not find method org.apache.batik.dom.svg.SVGDOMImplementation.getDOMImplementation, referenced from method org.apache.batik.dom.svg.SAXSVGDocumentFactory.<init>
03-17 20:26:37.688: WARN/dalvikvm(3632): VFY: unable to resolve static method 21646: Lorg/apache/batik/dom/svg/SVGDOMImplementation;.getDOMImplementation ()Lorg/w3c/dom/DOMImplementation;
03-17 20:26:37.688: DEBUG/dalvikvm(3632): VFY: replacing opcode 0x71 at 0x0000
03-17 20:26:37.688: INFO/dalvikvm(3632): Failed resolving Lorg/apache/batik/dom/ExtensibleDOMImplementation; interface 5043 'Lorg/w3c/dom/css/DOMImplementationCSS;'
03-17 20:26:37.688: WARN/dalvikvm(3632): Link of class 'Lorg/apache/batik/dom/ExtensibleDOMImplementation;' failed
03-17 20:26:37.688: WARN/dalvikvm(3632): Unable to resolve superclass of Lorg/apache/batik/dom/svg/SVGDOMImplementation; (2490)
03-17 20:26:37.688: WARN/dalvikvm(3632): Link of class 'Lorg/apache/batik/dom/svg/SVGDOMImplementation;' failed
03-17 20:26:37.688: INFO/dalvikvm(3632): Could not find method org.apache.batik.dom.svg.SVGDOMImplementation.getDOMImplementation, referenced from method org.apache.batik.dom.svg.SAXSVGDocumentFactory.<init>
03-17 20:26:37.688: WARN/dalvikvm(3632): VFY: unable to resolve static method 21646: Lorg/apache/batik/dom/svg/SVGDOMImplementation;.getDOMImplementation ()Lorg/w3c/dom/DOMImplementation;
03-17 20:26:37.688: DEBUG/dalvikvm(3632): VFY: replacing opcode 0x71 at 0x0000
03-17 20:26:37.698: INFO/dalvikvm(3632): Failed resolving Lorg/apache/batik/dom/AbstractDocument; interface 5227 'Lorg/w3c/dom/traversal/DocumentTraversal;'
03-17 20:26:37.698: WARN/dalvikvm(3632): Link of class 'Lorg/apache/batik/dom/AbstractDocument;' failed
03-17 20:26:37.698: WARN/dalvikvm(3632): Unable to resolve superclass of Lorg/apache/batik/dom/AbstractStylableDocument; (2467)
03-17 20:26:37.698: WARN/dalvikvm(3632): Link of class 'Lorg/apache/batik/dom/AbstractStylableDocument;' failed
03-17 20:26:37.698: WARN/dalvikvm(3632): Unable to resolve superclass of Lorg/apache/batik/dom/svg/SVGOMDocument; (2485)
03-17 20:26:37.698: WARN/dalvikvm(3632): Link of class 'Lorg/apache/batik/dom/svg/SVGOMDocument;' failed
03-17 20:26:37.698: ERROR/dalvikvm(3632): Could not find class 'org.apache.batik.dom.svg.SVGOMDocument', referenced from method org.apache.batik.dom.svg.SAXSVGDocumentFactory.createDocument
03-17 20:26:37.698: WARN/dalvikvm(3632): VFY: unable to resolve check-cast 2746 (Lorg/apache/batik/dom/svg/SVGOMDocument;) in Lorg/apache/batik/dom/svg/SAXSVGDocumentFactory;
03-17 20:26:37.698: DEBUG/dalvikvm(3632): VFY: replacing opcode 0x1f at 0x0062
03-17 20:26:37.698: INFO/dalvikvm(3632): Failed resolving Lorg/apache/batik/dom/AbstractDocument; interface 5227 'Lorg/w3c/dom/traversal/DocumentTraversal;'
03-17 20:26:37.698: WARN/dalvikvm(3632): Link of class 'Lorg/apache/batik/dom/AbstractDocument;' failed
03-17 20:26:37.698: WARN/dalvikvm(3632): Unable to resolve superclass of Lorg/apache/batik/dom/AbstractStylableDocument; (2467)
03-17 20:26:37.698: WARN/dalvikvm(3632): Link of class 'Lorg/apache/batik/dom/AbstractStylableDocument;' failed
03-17 20:26:37.698: WARN/dalvikvm(3632): Unable to resolve superclass of Lorg/apache/batik/dom/svg/SVGOMDocument; (2485)
03-17 20:26:37.698: WARN/dalvikvm(3632): Link of class 'Lorg/apache/batik/dom/svg/SVGOMDocument;' failed
03-17 20:26:37.698: ERROR/dalvikvm(3632): Could not find class 'org.apache.batik.dom.svg.SVGOMDocument', referenced from method org.apache.batik.dom.svg.SAXSVGDocumentFactory.createDocument
03-17 20:26:37.698: WARN/dalvikvm(3632): VFY: unable to resolve check-cast 2746 (Lorg/apache/batik/dom/svg/SVGOMDocument;) in Lorg/apache/batik/dom/svg/SAXSVGDocumentFactory;
03-17 20:26:37.698: DEBUG/dalvikvm(3632): VFY: replacing opcode 0x1f at 0x0013
03-17 20:26:37.698: INFO/dalvikvm(3632): Failed resolving Lorg/apache/batik/dom/AbstractDocument; interface 5227 'Lorg/w3c/dom/traversal/DocumentTraversal;'
03-17 20:26:37.698: WARN/dalvikvm(3632): Link of class 'Lorg/apache/batik/dom/AbstractDocument;' failed
03-17 20:26:37.698: ERROR/dalvikvm(3632): Could not find class 'org.apache.batik.dom.AbstractDocument', referenced from method org.apache.batik.dom.svg.SAXSVGDocumentFactory.createDocument
03-17 20:26:37.698: WARN/dalvikvm(3632): VFY: unable to resolve check-cast 2467 (Lorg/apache/batik/dom/AbstractDocument;) in Lorg/apache/batik/dom/svg/SAXSVGDocumentFactory;
03-17 20:26:37.698: DEBUG/dalvikvm(3632): VFY: replacing opcode 0x1f at 0x001f
03-17 20:26:37.698: INFO/dalvikvm(3632): Failed resolving Lorg/apache/batik/dom/AbstractDocument; interface 5227 'Lorg/w3c/dom/traversal/DocumentTraversal;'
03-17 20:26:37.698: WARN/dalvikvm(3632): Link of class 'Lorg/apache/batik/dom/AbstractDocument;' failed
03-17 20:26:37.698: WARN/dalvikvm(3632): Unable to resolve superclass of Lorg/apache/batik/dom/AbstractStylableDocument; (2467)
03-17 20:26:37.698: WARN/dalvikvm(3632): Link of class 'Lorg/apache/batik/dom/AbstractStylableDocument;' failed
03-17 20:26:37.698: WARN/dalvikvm(3632): Unable to resolve superclass of Lorg/apache/batik/dom/svg/SVGOMDocument; (2485)
03-17 20:26:37.698: WARN/dalvikvm(3632): Link of class 'Lorg/apache/batik/dom/svg/SVGOMDocument;' failed
03-17 20:26:37.698: ERROR/dalvikvm(3632): Could not find class 'org.apache.batik.dom.svg.SVGOMDocument', referenced from method org.apache.batik.dom.svg.SAXSVGDocumentFactory.createDocument
03-17 20:26:37.698: WARN/dalvikvm(3632): VFY: unable to resolve check-cast 2746 (Lorg/apache/batik/dom/svg/SVGOMDocument;) in Lorg/apache/batik/dom/svg/SAXSVGDocumentFactory;
03-17 20:26:37.698: DEBUG/dalvikvm(3632): VFY: replacing opcode 0x1f at 0x0013
03-17 20:26:37.698: INFO/dalvikvm(3632): Failed resolving Lorg/apache/batik/dom/AbstractDocument; interface 5227 'Lorg/w3c/dom/traversal/DocumentTraversal;'
03-17 20:26:37.698: WARN/dalvikvm(3632): Link of class 'Lorg/apache/batik/dom/AbstractDocument;' failed
03-17 20:26:37.698: ERROR/dalvikvm(3632): Could not find class 'org.apache.batik.dom.AbstractDocument', referenced from method org.apache.batik.dom.svg.SAXSVGDocumentFactory.createDocument
03-17 20:26:37.698: WARN/dalvikvm(3632): VFY: unable to resolve check-cast 2467 (Lorg/apache/batik/dom/AbstractDocument;) in Lorg/apache/batik/dom/svg/SAXSVGDocumentFactory;
03-17 20:26:37.698: DEBUG/dalvikvm(3632): VFY: replacing opcode 0x1f at 0x001f
03-17 20:26:37.698: INFO/dalvikvm(3632): Failed resolving Lorg/apache/batik/dom/ExtensibleDOMImplementation; interface 5043 'Lorg/w3c/dom/css/DOMImplementationCSS;'
03-17 20:26:37.698: WARN/dalvikvm(3632): Link of class 'Lorg/apache/batik/dom/ExtensibleDOMImplementation;' failed
03-17 20:26:37.698: WARN/dalvikvm(3632): Unable to resolve superclass of Lorg/apache/batik/dom/svg/SVGDOMImplementation; (2490)
03-17 20:26:37.698: WARN/dalvikvm(3632): Link of class 'Lorg/apache/batik/dom/svg/SVGDOMImplementation;' failed
03-17 20:26:37.698: INFO/dalvikvm(3632): Could not find method org.apache.batik.dom.svg.SVGDOMImplementation.getDOMImplementation, referenced from method org.apache.batik.dom.svg.SAXSVGDocumentFactory.getDOMImplementation
03-17 20:26:37.698: WARN/dalvikvm(3632): VFY: unable to resolve static method 21646: Lorg/apache/batik/dom/svg/SVGDOMImplementation;.getDOMImplementation ()Lorg/w3c/dom/DOMImplementation;
03-17 20:26:37.698: DEBUG/dalvikvm(3632): VFY: replacing opcode 0x71 at 0x0018
03-17 20:26:37.698: INFO/dalvikvm(3632): Failed resolving Lorg/apache/batik/dom/ExtensibleDOMImplementation; interface 5043 'Lorg/w3c/dom/css/DOMImplementationCSS;'
03-17 20:26:37.698: WARN/dalvikvm(3632): Link of class 'Lorg/apache/batik/dom/ExtensibleDOMImplementation;' failed
03-17 20:26:37.698: WARN/dalvikvm(3632): Unable to resolve superclass of Lorg/apache/batik/dom/svg/SVGDOMImplementation; (2490)
03-17 20:26:37.698: WARN/dalvikvm(3632): Link of class 'Lorg/apache/batik/dom/svg/SVGDOMImplementation;' failed
03-17 20:26:37.698: WARN/dalvikvm(3632): Unable to resolve superclass of Lorg/apache/batik/dom/svg12/SVG12DOMImplementation; (2676)
03-17 20:26:37.698: WARN/dalvikvm(3632): Link of class 'Lorg/apache/batik/dom/svg12/SVG12DOMImplementation;' failed
03-17 20:26:37.698: INFO/dalvikvm(3632): Could not find method org.apache.batik.dom.svg12.SVG12DOMImplementation.getDOMImplementation, referenced from method org.apache.batik.dom.svg.SAXSVGDocumentFactory.getDOMImplementation
03-17 20:26:37.698: WARN/dalvikvm(3632): VFY: unable to resolve static method 23668: Lorg/apache/batik/dom/svg12/SVG12DOMImplementation;.getDOMImplementation ()Lorg/w3c/dom/DOMImplementation;
03-17 20:26:37.698: DEBUG/dalvikvm(3632): VFY: replacing opcode 0x71 at 0x0025
03-17 20:26:37.728: WARN/dalvikvm(3632): threadid=10: thread exiting with uncaught exception (group=0x313c61f8)
Also, there are a lot of warnings on make:
What causes this problem?
回答1:
Batik uses Java2D API, which is unavailable on Android. You need to use another library.
来源:https://stackoverflow.com/questions/22463600/java-lang-noclassdeffounderror-org-apache-batik-dom-svg-svgdomimplementation