2
E/AndroidRuntime: FATAL EXCEPTION: main
 Process: be.kdg.examen, PID: 4451
 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{be.kdg.examen/be.kdg.examen.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "be.kdg.examen.MainActivity" on path: DexPathList[[zip file "/data/app/be.kdg.examen-1/base.apk"],nativeLibraryDirectories=[/data/app/be.kdg.examen-1/lib/x86, /system/lib, /vendor/lib]]
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2567)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
     at android.app.ActivityThread.-wrap12(ActivityThread.java)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
     at android.os.Handler.dispatchMessage(Handler.java:102)
     at android.os.Looper.loop(Looper.java:154)
     at android.app.ActivityThread.main(ActivityThread.java:6119)
     at java.lang.reflect.Method.invoke(Native Method)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
  Caused by: java.lang.ClassNotFoundException: Didn't find class "be.kdg.examen.MainActivity" on path: DexPathList[[zip file "/data/app/be.kdg.examen-1/base.apk"],nativeLibraryDirectories=[/data/app/be.kdg.examen-1/lib/x86, /system/lib, /vendor/lib]]
     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
     at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2557)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
     at android.app.ActivityThread.-wrap12(ActivityThread.java) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:154) 
     at android.app.ActivityThread.main(ActivityThread.java:6119) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 

I always get this error while trying to run the application. There is a MainActivity so I really don't know what the problem is.

This is the file structure

user1506104
  • 6,554
  • 4
  • 71
  • 89
Souf
  • 369
  • 2
  • 16

3 Answers3

4

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:)

Kathir
  • 1,282
  • 1
  • 15
  • 19
Bhuvanesh BS
  • 13,474
  • 12
  • 40
  • 66
2

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

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

Michael Meyer
  • 2,179
  • 3
  • 24
  • 33
1

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

Kapil G
  • 4,081
  • 2
  • 20
  • 32