AccessibilityService ClassNotFoundExcepiton

今天在学习AccessiblityService,简单的几部操作,但是当辅助功能里开启服务时一直报ClassNotFoundException,异常如下(写这篇blog时,错误信息已经没了,从网上直接找粘贴的一个,错误信息跟我的一样):
FATAL EXCEPTION: main
Process: com.edr.iveflownthat, PID: 1457
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/edr/iveflownthat/TempLobbyActivity;
    at com.edr.iveflownthat.pages.MainActivity.tryAutoLogin(MainActivity.java:46)
    at com.edr.iveflownthat.pages.MainActivity.onCreate(MainActivity.java:22)
    at android.app.Activity.performCreate(Activity.java:5933)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
    at android.app.ActivityThread.access$800(ActivityThread.java:144)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5221)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.ClassNotFoundException: Didn't find class     "com.edr.iveflownthat.TempLobbyActivity" on path: DexPathList[[zip file "/data/app/com.edr.iveflownthat-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
FATAL EXCEPTION: main
Process: com.edr.iveflownthat, PID: 1457
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/edr/iveflownthat/TempLobbyActivity;
    at com.edr.iveflownthat.pages.MainActivity.tryAutoLogin(MainActivity.java:46)
    at com.edr.iveflownthat.pages.MainActivity.onCreate(MainActivity.java:22)
    at android.app.Activity.performCreate(Activity.java:5933)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
    at android.app.ActivityThread.access$800(ActivityThread.java:144)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5221)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.edr.iveflownthat.TempLobbyActivity" on path: DexPathList[[zip file "/data/app/com.edr.iveflownthat-1/base.apk"],nativeLibraryDirectories=[/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)
    ... 15 more
Suppressed: java.lang.NoClassDefFoundError: com.edr.iveflownthat.TempLobbyActivity
    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:321)
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
    ... 17 more
Suppressed: java.lang.ClassNotFoundException: com.edr.iveflownthat.TempLobbyActivity
    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)
    ... 16 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    ... 15 more
Suppressed: java.lang.NoClassDefFoundError: com.edr.iveflownthat.TempLobbyActivity
    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:321)
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
    ... 17 more
Suppressed: java.lang.ClassNotFoundException: com.edr.iveflownthat.TempLobbyActivity
    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)
    ... 16 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
最后,突发灵感,想到我在创建项目时,没有像往常一样直接创建一个MainActivity.java,创建项目之后重新创建了一个和应用包名一样的package,在里面放置我的类,致使在调用的时候找不到我的类,不知道为什么这么做不行,但是知道错误的原因了。
so,赶快重新建了一个项目,创建项目的时候直接创建一个类,也就是创建一个和应用包名一样的package

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。