Search code examples
javaandroidclassnotfoundexception

ClassNotFoundException: Didn't find class "package.MainActivity" on brand new project


This is terribly frustrating. I have created new project in Android Studio - Empty Activity template so i get one Activity file with its layout file where is one TextView. When i launch the project i get this error:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{package/package.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "package.MainActivity" on path: DexPathList[[zip file "/data/app/package-2.apk"],nativeLibraryDirectories=[/data/app-lib/package-2, /vendor/lib, /system/lib]]

I tried File -> Invalidate Caches / Restart it didn't help.

It is astounding why some error happens on brand new template project.. I am confused..

I created two new projects, it happens on both of them.


Solution

  • Once it happened to me as well. I just cleaned the project and rebuilt it and everything then went perfect so I suggest you do the same.

    Follow below steps:

    1. select build (this option is available on the top of android studio)
    2. select clean project and wait for gradle process end
    3. once gradle process ends rebuild it.

    Hope it helps you.