Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 680
Uğur Avatar asked Nov 05 '14 22:11

Uğur


3 Answers

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

like image 134
Jorgesys Avatar answered Nov 13 '22 04:11

Jorgesys


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'
like image 45
Hamza Khan Avatar answered Nov 13 '22 06:11

Hamza Khan


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.

like image 32
EmmanuelMess Avatar answered Nov 13 '22 06:11

EmmanuelMess