gpt4 book ai didi

java - Android + jfreeSVG : inheritance issues

转载 作者:行者123 更新时间:2023-11-30 02:52:53 27 4
gpt4 key购买 nike

我正在使用 Android Studio 开发 Android 应用程序。该应用程序使用全java 库模块。我已经包括了jfreesvg通过将 compile 'org.jfree:jfreesvg:3.1' 添加到所述 java 库模块的依赖项。

在该 java 库中,我正在尝试主 doc 中给定的示例。对于SVGGraphics2D:

    SVGGraphics2D g2 = new SVGGraphics2D(300, 200);
g2.setPaint(Color.black);
g2.draw(new Rectangle(10, 10, 280, 180));
String svgElement = g2.getSVGElement();

但是,我在 Android Studio 中遇到两个编译错误,第一个错误位于第二行:SVGGraphics2D 中的 setPaint(java.awt.Paint) 无法应用于 (java.awt.Color)

此外,在下一行中,出现以下错误,我认为发生的原因相同:SVGGraphics2D 中的draw(java.awt.Paint) 无法应用于(java.awt.Color)

我现在的问题是:即使java.awt.Paint是一个接口(interface)并且 java.awt.Color是该接口(interface)的实现,为什么我会收到该错误(对于 java.awt.Shapejava.awt.Rectangle 也是如此)?

为了完成:如果我运行该应用程序(我对它的工作原理感到困惑),我会收到以下异常:

E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: [package].app, PID: 19596
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:811)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jfree/graphics2d/svg/SVGGraphics2D;
at [package].[some.package].someMethod(Unknown)
at [package].app.MainActivity$SomeTask.doInBackground(MainActivity.java:67)
at [package].app.MainActivity$SomeTask.doInBackground(MainActivity.java:62)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
at java.lang.Thread.run(Thread.java:811) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.jfree.graphics2d.svg.SVGGraphics2D" on path: DexPathList[[zip file "/data/app/[package].app-2.apk"],nativeLibraryDirectories=[/data/app-lib/[package].app-2, /system/lib, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at [package].[some.package].someMethod(Unknown) 
at [package].app.MainActivity$SomeTask.doInBackground(MainActivity.java:67) 
at [package].app.MainActivity$SomeTask.doInBackground(MainActivity.java:62) 
at android.os.AsyncTask$2.call(AsyncTask.java:288) 
at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
at java.lang.Thread.run(Thread.java:811) 
Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/awt/Graphics2D;
at dalvik.system.DexFile.defineClassNative(Native Method)
at dalvik.system.DexFile.defineClass(DexFile.java:222)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:215)
at dalvik.system.DexPathList.findClass(DexPathList.java:322)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
... 11 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.awt.Graphics2D" on path: DexPathList[[zip file "/data/app/[package].app-2.apk"],nativeLibraryDirectories=[/data/app-lib/[package].app-2, /system/lib, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
... 16 more
Suppressed: java.lang.ClassNotFoundException: java.awt.Graphics2D
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 17 more
Caused by: java.lang.NoClassDefFoundError: Class "Ljava/awt/Graphics2D;" not found
... 21 more
Suppressed: java.lang.ClassNotFoundException: org.jfree.graphics2d.svg.SVGGraphics2D
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 10 more
Caused by: java.lang.NoClassDefFoundError: Class "Lorg/jfree/graphics2d/svg/SVGGraphics2D;" not found
... 14 more

(我编辑了堆栈跟踪以获得更好的可读性。)

最佳答案

java.awt.* 包在 Android 中不可用。因此,您尝试使用的库不能直接在您的 Android 应用程序中使用。至少在没有进一步工作的情况下是这样。

您需要自己实现这些类,或者从其他地方获取它们,例如从 Apache Harmony 项目。

关于java - Android + jfreeSVG : inheritance issues,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38119935/

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