Java.lang.RuntimeException: Unable to instantiate Activity ComponentInfo {...}: java.lang.ClassNotFoundException: could not find class

I am developing an application using the Fuse Location Provider. I get the error "Sorry, appname has stopped" when I try to start the program. Eclipse does not show that there are errors, but there are errors in logcat. I do not know how to fix them. I downloaded the source code here . Please help me 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 
+5
source share
5 answers

Since your exception is:

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

in your AndroidManifest.xml add the full package in which your activity is located:

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

or be sure to correct the package name:

 package="com.kpbird.fusedlocation" 

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

enter image description here

+2
source

This happened when I moved the application from one directory to another once, if @Jorgesys solution does not help, consider renaming the module and clearing the project. Note. I used Android Studio.

+1
source

The same thing happens when you include AndroidManifest in a link with:

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

and the wrong google_play_services_version value.

0
source

When updating the MainActivity.java file, I accidentally changed the name package com.ppg; from package com.ppg; for package com.PPG; (upper case instead of lower case). When I returned to lowercase, it started working.

0
source

Having spent a lot of time on this problem, I finally got a solution.

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

100% it will be resolved.

-5
source

Source: https://habr.com/ru/post/1206297/


All Articles