gpt4 book ai didi

java - 致命异常 NoClassDefFoundError

转载 作者:行者123 更新时间:2023-11-29 20:05:26 24 4
gpt4 key购买 nike

在 Android 中我想执行一个脚本。所以我从

添加了 JavaScript 引擎

http://www.java2s.com/Code/JarDownload/jsr223/jsr223.jar.zip

我的 gradle(模块:app)说:

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.google.apis:google-api-services-youtube:v3-rev162-1.21.0'
compile 'joda-time:joda-time:2.3'
compile files('libs/jsr223.jar')
}

如果我正在运行应用程序并单击初始化脚本引擎的按钮,我会收到以下错误。

有什么解决办法吗?

E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2     
Process: com.myApplication, PID: 25387
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:304)
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:818)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lsun/misc/Service;
at javax.script.ScriptEngineManager.initEngines(ScriptEngineManager.java:90)
at javax.script.ScriptEngineManager.access$0(ScriptEngineManager.java:86)
at javax.script.ScriptEngineManager$1.run(ScriptEngineManager.java:80)
at java.security.AccessController.doPrivileged(AccessController.java:45)
at javax.script.ScriptEngineManager.init(ScriptEngineManager.java:78)
at javax.script.ScriptEngineManager.<init>(ScriptEngineManager.java:51)
at com.linkgrabber.LinkgrabberSecured.getDecodedSignature(LinkgrabberSecured.java:202)
at com.linkgrabber.LinkgrabberSecured.getHttpLinks(LinkgrabberSecured.java:65)
at com.myApplication.MainActivity$AsyncLinkGrabber.doInBackground(MainActivity.java:651)
at com.myApplication.MainActivity$AsyncLinkGrabber.doInBackground(MainActivity.java:637)
at android.os.AsyncTask$2.call(AsyncTask.java:292)
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:818) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "sun.misc.Service" on path: DexPathList[[zip file "/data/app/com.myApplication-2/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
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 javax.script.ScriptEngineManager.initEngines(ScriptEngineManager.java:90) 
at javax.script.ScriptEngineManager.access$0(ScriptEngineManager.java:86) 
at javax.script.ScriptEngineManager$1.run(ScriptEngineManager.java:80) 
at java.security.AccessController.doPrivileged(AccessController.java:45) 
at javax.script.ScriptEngineManager.init(ScriptEngineManager.java:78) 
at javax.script.ScriptEngineManager.<init>(ScriptEngineManager.java:51) 
at com.linkgrabber.LinkgrabberSecured.getDecodedSignature(LinkgrabberSecured.java:202) 
at com.linkgrabber.LinkgrabberSecured.getHttpLinks(LinkgrabberSecured.java:65) 
at com.myApplication.MainActivity$AsyncLinkGrabber.doInBackground(MainActivity.java:651) 
at com.myApplication.MainActivity$AsyncLinkGrabber.doInBackground(MainActivity.java:637) 
at android.os.AsyncTask$2.call(AsyncTask.java:292) 
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:818) 
Suppressed: java.lang.ClassNotFoundException: sun.misc.Service
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 not found using the boot class loader; no stack available

最佳答案

您正在导入 sun.misc.service。我想你可能是指 android.app.Service。结果你无法加载它(android 不包含 sun.misc.Service)。要么,要么您需要将其与您的应用程序打包在一起。

关于java - 致命异常 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35734815/

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