2017-03-29 53 views
0

我與Android工作室工作的一個學習應用程序,但是當我運行它,它崩潰並給我這個錯誤代碼:ClassNotFoundException的應用程序和崩潰

03-29 22:36:03.546 13455-13455/com.training.criminalintent E/AndroidRuntime: FATAL EXCEPTION: main 
Process: com.training.criminalintent, PID: 13455 
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.training.criminalintent/com.training.criminalintent.CrimeListActivity}: java.lang.ClassNotFoundException: Didn't find class "com.training.criminalintent.CrimeListActivity" on path: DexPathList[[zip file "/data/app/com.training.criminalintent-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]] 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2290) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442) 
    at android.app.ActivityThread.access$800(ActivityThread.java:156) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:211) 
    at android.app.ActivityThread.main(ActivityThread.java:5371) 
    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:945) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:740) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.training.criminalintent.CrimeListActivity" on path: DexPathList[[zip file "/data/app/com.training.criminalintent-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) 
    at android.app.Instrumentation.newActivity(Instrumentation.java:1066) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2280) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442) 
    at android.app.ActivityThread.access$800(ActivityThread.java:156) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:211) 
    at android.app.ActivityThread.main(ActivityThread.java:5371) 
    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:945) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:740) 
Suppressed: java.lang.ClassNotFoundException: com.training.criminalintent.CrimeListActivity 
    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) 
     ... 13 more 
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available 

我找了一個解決方案,但沒有爲android工作室找到足夠的東西,但最重要的是,我沒有找到問題的根源,爲什麼android studio的行爲如此。

編輯:活動存在於清單文件:

<application 
>  android:allowBackup="true" 
>  android:icon="@mipmap/ic_launcher" 
>  android:label="@string/app_name" 
>  android:supportsRtl="true" 
>  android:theme="@style/AppTheme"> 
>  <activity android:name=".CrimeListActivity"> 
>   <intent-filter> 
>    <action android:name="android.intent.action.MAIN" /> 
>    <category android:name="android.intent.category.LAUNCHER" /> 
>   </intent-filter> 
>  </activity> 
>  <activity android:name=".CrimePagerActivity"> 
>  </activity> </application> 

我還必須準確,以前我降級的工具文件夾中的SDK(與其他軟件的兼容性問題) [我命名文件夾工具==> toolsXXXX並下載版本24.2並將工具文件夾放在sdk文件夾中],它正在工作..

+1

@EvilZ回答了你的問題;但是這裏有一個鏈接(https://github.com/mehtamanan/CriminalIntent)給你正在構建的整個項目! –

+0

謝謝,但我對學習不是項目本身感興趣。 –

回答

0

嘗試執行應用程序的卸載,執行清理生成,gradle同步,然後再次運行應用程序。

+0

我試過了,但問題依然存在 –

0

確保com.training.criminalintent.CrimeListActivity存在於您的AndroidManifest.xml中。

<activity android:name="com.training.criminalintent.CrimeListActivity" />