Android: ClassNotFoundException while class is present

后端 未结 3 1074
鱼传尺愫
鱼传尺愫 2020-12-18 14:39
E/AndroidRuntime: FATAL EXCEPTION: main
 Process: be.kdg.examen, PID: 4451
 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{be.kdg.examen/be         


        
相关标签:
3条回答
  • 2020-12-18 14:47

    it is looking for the class in the package be.kdg.examen.MainActivity whereas your MainActivity is in be.kdg.examen.vraag5.MainActivity

    Please check what is the complete path mentioned in your AndroidManifest.xml file if its mentioned as .MainActivity change it to .vraag5.MainActivity

    0 讨论(0)
  • 2020-12-18 14:51

    You have to include multiDex in your application. This can be inferred from the following line of your logcat output:

    java.lang.ClassNotFoundException: Didn't find class "be.kdg.examen.MainActivity" on path: DexPathList[
    

    What is multiDex and how does this solution solve the problem?

    Read this answer to understand.


    The Solution

    Step 1: Add this to your dependencies.

     implementation 'com.android.support:multidex:1.0.1'
    

    Step 2: In your Gradle add multiDexEnabled true.

    android {
        defaultConfig {
            ...
            minSdkVersion 21 
            targetSdkVersion 26
            multiDexEnabled true    // add this line
        }
        ...
    }
    

    Step 3: In your manifest add multiDex application class.

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.myapp">
        <application
                android:name="android.support.multidex.MultiDexApplication" >
            ...
        </application>
    </manifest>
    

    Hope it helps:)

    0 讨论(0)
  • 2020-12-18 15:02

    This seems to be a problem with the multidex support. Please see the following thread

    FATAL EXCEPTION: main java.lang.NoClassDefFoundError: rx.plugins.RxJavaHooks

    0 讨论(0)
提交回复
热议问题