Home » Android » java.lang.ClassNotFoundException on my android app but I have no idea why

java.lang.ClassNotFoundException on my android app but I have no idea why

Posted by: admin June 15, 2020 Leave a comment

Questions:

I’ve been trying to get started with Android programming for a while now. I’m mainly a .NET developer with no Java experience for 8 years (university).

I can compile and run samples no problem but the moment I try and rename my package/class it fails. I believe I’ve updated the manifest and triple checked it (Copied and pasted name, selected it with Eclipse) yet it always fails with a java.lang.ClassNotFoundException:


12-02 09:12:21.088: ERROR/AndroidRuntime(233): Uncaught handler: thread main exiting due to uncaught exception
12-02 09:12:21.178: ERROR/AndroidRuntime(233): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.anddev.cheesemp.helloandworld/org.anddev.cheesemp.helloandworld.HelloAndEngine}: java.lang.ClassNotFoundException: org.anddev.cheesemp.helloandworld.HelloAndEngine in loader [email protected]
12-02 09:12:21.178: ERROR/AndroidRuntime(233):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
12-02 09:12:21.178: ERROR/AndroidRuntime(233):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
12-02 09:12:21.178: ERROR/AndroidRuntime(233):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
12-02 09:12:21.178: ERROR/AndroidRuntime(233):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
12-02 09:12:21.178: ERROR/AndroidRuntime(233):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-02 09:12:21.178: ERROR/AndroidRuntime(233):     at android.os.Looper.loop(Looper.java:123)
12-02 09:12:21.178: ERROR/AndroidRuntime(233):     at android.app.ActivityThread.main(ActivityThread.java:4363)
12-02 09:12:21.178: ERROR/AndroidRuntime(233):     at java.lang.reflect.Method.invokeNative(Native Method)
12-02 09:12:21.178: ERROR/AndroidRuntime(233):     at java.lang.reflect.Method.invoke(Method.java:521)
12-02 09:12:21.178: ERROR/AndroidRuntime(233):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-02 09:12:21.178: ERROR/AndroidRuntime(233):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-02 09:12:21.178: ERROR/AndroidRuntime(233):     at dalvik.system.NativeStart.main(Native Method)
12-02 09:12:21.178: ERROR/AndroidRuntime(233): Caused by: java.lang.ClassNotFoundException: org.anddev.cheesemp.helloandworld.HelloAndEngine in loader [email protected]
12-02 09:12:21.178: ERROR/AndroidRuntime(233):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
12-02 09:12:21.178: ERROR/AndroidRuntime(233):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
12-02 09:12:21.178: ERROR/AndroidRuntime(233):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
12-02 09:12:21.178: ERROR/AndroidRuntime(233):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
12-02 09:12:21.178: ERROR/AndroidRuntime(233):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
12-02 09:12:21.178: ERROR/AndroidRuntime(233):     ... 11 more

Manifest is here:


<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0" package="org.anddev.cheesemp.helloandworld">
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:label="@string/app_name" android:name="org.anddev.cheesemp.helloandworld.HelloAndEngine">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="4" \>
</manifest>

Class definition is here:


package org.anddev.cheesemp.helloandworld;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.background.ColorBackground;
import org.anddev.andengine.entity.text.Text;
import org.anddev.andengine.entity.util.FPSLogger;
import org.anddev.andengine.opengl.font.Font;
import org.anddev.andengine.opengl.texture.Texture;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.ui.activity.BaseGameActivity;
import org.anddev.andengine.util.HorizontalAlign;

import android.graphics.Color;
import android.graphics.Typeface;

/**
 * @author Nicolas Gramlich
 * @since 11:54:51 - 03.04.2010
 */
public class HelloAndEngine extends BaseGameActivity

This sample is from AndEngine but I’ve had the same issue with every sample I modify. I can’t help but feel I’ve missed something and nothing I found searching has helped.

Any advice appreciated!

How to&Answers:

Try this.

<activity android:label="@string/app_name" android:name=".HelloAndEngine">

You don’t need the fully qualified class name. Also, if you are working with Eclipse and rename a package go to ProjectClean and let it clean up your project, fixing up references and so on if anything is broken.

Answer:

This is a bug in eclipse android tools
http://code.google.com/p/android/issues/detail?id=2824

To Fix -> Right click on the project go to Android tools -> Rename application package..

And also check AndroidManifest.xml if it updated correctly, in my case it didn’t, that should solve this problem