放牧代码和思想
专注自然语言处理、机器学习算法
    愛しさ 優しさ すべて投げ出してもいい

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自然语言处理包《自然语言处理入门》