Uğur
Uğur

Reputation: 115

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{…}: java.lang.ClassNotFoundException: Didn't find class

I am developing an app using Fused Location Provider. I am getting an error "Unfortunately, appname has stopped" when i attempt to run the program. Eclipse doesnt show that there are any mistakes but there are errors in the logcat. I dont know how to fix them. I downloaded source code here. Please help me to understand what I did wrong?

LogCat

11-05 08:31:41.641: E/AndroidRuntime(795): FATAL EXCEPTION: main
11-05 08:31:41.641: E/AndroidRuntime(795): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.kpbird.fusedlocation/com.kpbird.fusedlocation.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.kpbird.fusedlocation.MainActivity" on path: DexPathList[[zip file "/data/app/com.kpbird.fusedlocation-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.kpbird.fusedlocation-1, /system/lib]]
11-05 08:31:41.641: E/AndroidRuntime(795):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
11-05 08:31:41.641: E/AndroidRuntime(795):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
11-05 08:31:41.641: E/AndroidRuntime(795):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
11-05 08:31:41.641: E/AndroidRuntime(795):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
11-05 08:31:41.641: E/AndroidRuntime(795):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-05 08:31:41.641: E/AndroidRuntime(795):  at android.os.Looper.loop(Looper.java:137)
11-05 08:31:41.641: E/AndroidRuntime(795):  at android.app.ActivityThread.main(ActivityThread.java:5103)
11-05 08:31:41.641: E/AndroidRuntime(795):  at java.lang.reflect.Method.invokeNative(Native Method)
11-05 08:31:41.641: E/AndroidRuntime(795):  at java.lang.reflect.Method.invoke(Method.java:525)
11-05 08:31:41.641: E/AndroidRuntime(795):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-05 08:31:41.641: E/AndroidRuntime(795):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-05 08:31:41.641: E/AndroidRuntime(795):  at dalvik.system.NativeStart.main(Native Method)
11-05 08:31:41.641: E/AndroidRuntime(795): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.kpbird.fusedlocation.MainActivity" on path: DexPathList[[zip file "/data/app/com.kpbird.fusedlocation-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.kpbird.fusedlocation-1, /system/lib]]
11-05 08:31:41.641: E/AndroidRuntime(795):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
11-05 08:31:41.641: E/AndroidRuntime(795):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-05 08:31:41.641: E/AndroidRuntime(795):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-05 08:31:41.641: E/AndroidRuntime(795):  at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
11-05 08:31:41.641: E/AndroidRuntime(795):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
11-05 08:31:41.641: E/AndroidRuntime(795):  ... 11 more

Upvotes: 11

Views: 22585

Answers (7)

Vicky Leekha
Vicky Leekha

Reputation: 61

This error occurred when you change package name in manifest file but not in main activity . remember when you changing package name then change it on 1 manifest file if your building flutter then change it on all 3 mode profile , debug , and release 2 main activity kotlin or java file

3 In build gradle change the application id

Upvotes: 1

Hamza Khan
Hamza Khan

Reputation: 1521

In my case the issue was with gradle

I refactored my code from java to kotlin but forgot to add this in Gradle

apply plugin: 'kotlin-android'

Upvotes: 12

AnR
AnR

Reputation: 2215

While updating my MainActivity.java I accidentally changed my package name from package com.ppg; to package com.PPG; (upper case instead of lower case). When I changed back to lower case it started working.

Upvotes: 0

EmmanuelMess
EmmanuelMess

Reputation: 1143

This happened when I moved an app from one directory to another once, if @Jorgesys's solution doesn't help, consider renaming the module and cleaning the project. Note: I was using Android Studio.

Upvotes: 1

Mehul
Mehul

Reputation: 2149

After spending much time on this problem i finally got the solution.

Just remove setContentView(R.layout.LAYOUT_NAME); from constructor of class and put it into onCreate method of the class.

100% it will be solved.

Upvotes: -6

Jacob
Jacob

Reputation: 15297

The same issue occurs while including in AndroidManifest reference with:

  <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

and hardcoded wrong google_play_services_version value.

Upvotes: 0

Jorgesys
Jorgesys

Reputation: 126455

Since your exception is:

ClassNotFoundException: Didn't find class "com.kpbird.fusedlocation.MainActivity"

into your AndroidManifest.xml add the complete package were your activity is located:

<activity
                android:name="com.kpbird.fusedlocation.MainActivity"

or be sure to have to correct package name defined:

package="com.kpbird.fusedlocation"

I think you typed incorrectly the package of your application in some place of your code!

enter image description here

Upvotes: 10

Related Questions