致命的NoClassDefFoundError

时间:2016-03-01 22:23:23

标签: java android exception fatal-error javascript-engine

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     

1 个答案:

答案 0 :(得分:2)

您正在导入sun.misc.service。我想你可能是指android.app.Service。因此,您无法加载它(android不包括sun.misc.Service)。或者您需要将其与您的应用打包。