Android Studio: ClassNotFoundException

后端 未结 17 893
时光说笑
时光说笑 2021-01-11 13:23

i was busy with my app for over a week, when suddenly:

11-12 07:59:17.860    1653-1653/nl.test.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.Runtim         


        
相关标签:
17条回答
  • 2021-01-11 14:14
       try: 
       <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    
    0 讨论(0)
  • 2021-01-11 14:14

    https://stackoverflow.com/a/29821331/11480535 worked for me with the little addition that I also had to delete the projectFilesBackup/!

    0 讨论(0)
  • 2021-01-11 14:15

    I had the same problem, turns out I screwed up with some final method. Be sure to check dalvikvm errors in logcat output before the FATAL EXCEPTION. I will give you some hints on the problem. In my case, I had a final method (isResumed) which was already defined in the base class - causing runtime crash. Wasn't complaining at compile time.

    Check the logs:

    E/dalvikvm( 9984): Method Lcom/your/package/ui/SomeActivity;.isResumed overrides final Landroid/app/Activity;.isResumed
    W/dalvikvm( 9984): failed creating vtable
    ...
    D/AndroidRuntime( 9962): Shutting down VM
    ...
    E/AndroidRuntime(10065): FATAL EXCEPTION: main
    E/AndroidRuntime(10065): Process: com.yourpackage.ui, PID: 10065
    E/AndroidRuntime(10065): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.yourpackage.ui/com.yourpackage.ui.HomeActivity}: java.lang.ClassNotFoundException: Didn't find class "com.yourpackage.ui.HomeActivity" on path: DexPathList[[zip file "/data/app/com.yourpackage.ui-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.yourpackage.ui-2, /vendor/lib, /system/lib]]
    ...
    
    0 讨论(0)
  • 2021-01-11 14:15

    You can check Multidex mechanism. The reason may be method numbers overflow.

    1. Add MultiDex.install(this); to your Application:

      @Override
      protected void attachBaseContext(Context base) {
           super.attachBaseContext(base);
           MultiDex.install(this);
      }
      
    2. and add

      afterEvaluate {
         tasks.matching {
             it.name.startsWith('dex')
         }.each { dx ->
             if (dx.additionalParameters == null) {
                 dx.additionalParameters = []
             }
             dx.additionalParameters += '--multi-dex' // enable multidex
         }
      }
      

    to your app module's gradle.build

    0 讨论(0)
  • 2021-01-11 14:18

    i don't know this will help you..anyway try to use application theme as @style/Theme.AppCompat..we must use as per developers forum.

    <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/Theme.AppCompat" >
    
           <activity
                android:name=".MainActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    
    0 讨论(0)
提交回复
热议问题