Android Studio:无法实例化活动ComponentInfo..ClassNotFoundException

时间:2015-08-15 04:33:28

标签: android

我使用Android Studio 1.2创建了一个新项目,然后运行它,但它无法正常工作。错误如下:

com.example.android.lifecycle E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.android.lifecycle, PID: 8674
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android.lifecycle/com.example.android.lifecycle.ActivityA}: java.lang.ClassNotFoundException: Didn't find class "com.example.android.lifecycle.ActivityA" on path: DexPathList[[zip file "/data/app/com.example.android.lifecycle-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2236)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
    at android.app.ActivityThread.access$800(ActivityThread.java:151)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5257)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)

Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

1 个答案:

答案 0 :(得分:0)

我重新安装Android Studio并升级到1.3.1,但预先创建的项目也无法正常工作。通过比较项目和新项目,我找到了解决方案:

  1. 所有活动都扩展了AppCompatActivity
  2. 项目的build.gradle应该依赖gradle:1.3.0
  3. distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
  4. 我尝试了这些差异,发现当我将distributionUrl更改为2.4版本时,一切都很顺利。