放牧代码和思想
专注自然语言处理、机器学习算法
    博主不用扣扣,公事请博客留言,私事请微博私信。开源项目一律GitHub见,发错地方恕不回复,谢谢。

Caused by: java.lang.ClassNotFoundException: Didn’t find class on path apk IntelliJ IDEA解决方案

这个错误是由于library工程没有指定造成的。

今天用IntelliJ IDEA导入了Git上的一个项目后编译报错:

12-28 03:52:07.359    2336-2336/me.imid.swipebacklayout.demo E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{me.imid.swipebacklayout.demo/me.imid.swipebacklayout.demo.DemoActivity}: java.lang.ClassNotFoundException: Didn't find class "me.imid.swipebacklayout.demo.DemoActivity" on path: /data/app/me.imid.swipebacklayout.demo-1.apk
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5041)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "me.imid.swipebacklayout.demo.DemoActivity" on path: /data/app/me.imid.swipebacklayout.demo-1.apk
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
            at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5041)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
            at dalvik.system.NativeStart.main(Native Method)

自己在out路径下找到了相应的activity.class文件,可是运行时偏偏就是找不到这个activity.class。检查了/AndroidManifest.xml,发现一切正常。自己新建了项目,将模块以library module导入,依然报错java.lang.ClassNotFoundException。最后发现原来是因为自己没有指定哪一个模块是library module,很是浪费了一些时间。

解决方案很简单,打开Project Structure,打开Facets,勾选library mode:

之后编译就正常了。

转载须注明:码农场 » Caused by: java.lang.ClassNotFoundException: Didn’t find class on path apk IntelliJ IDEA解决方案

分享到:更多 ()

我的开源项目

HanLP自然语言处理包基于DoubleArrayTrie的Aho Corasick自动机