8

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 dalvik.system.PathClassLoader@43d0c0d0
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 dalvik.system.PathClassLoader@43d0c0d0
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!

cheesemp
  • 307
  • 1
  • 3
  • 10

2 Answers2

18

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.

Octavian Helm
  • 39,405
  • 19
  • 98
  • 102
  • 1
    Well, the "." at the beginning will implicitly prepend the full package name. – EboMike Dec 02 '10 at 09:44
  • @EboMike: Exactly. Why would he need the full package name? He just doesn't. – Octavian Helm Dec 02 '10 at 09:46
  • True, it's definitely preferred to just use the period. But will this solve the problem? The issue is that the class loader can't find the class org.anddev.cheesemp.helloandworld.HelloAndEngine, which SEEMS to be present. – EboMike Dec 02 '10 at 09:48
  • @EboMike: True. I forgot to mention that a project cleanup should help. – Octavian Helm Dec 02 '10 at 09:50
  • Wow, I missed that in the question. Yeah, renaming is bad juju. Cleaning it should do the trick. – EboMike Dec 02 '10 at 09:51
  • I've tried cleaning several times. The fully qualified name was entered by Eclipse. I originally had .HelloAndEngine before selecting the class with eclipse. – cheesemp Dec 02 '10 at 09:59
  • @cheesemp: What was the old name and what is the new name? I mean the package name. – Octavian Helm Dec 02 '10 at 10:01
  • Original package name was com.example.helloAndEngine. New name is org.anddev.cheesemp.helloandworld. I have cleared out the old R.java that was generated under the old name. The new R.java is being correctly generated under the new name. – cheesemp Dec 02 '10 at 10:08
  • The error says that your class loader could not load the class `org.anddev.cheesemp.helloandworld.HelloAndEngine`. That means that for whatever reason, this class is not part of your project. Did something really weird happen that caused the .java file not to be part of the project? – EboMike Dec 02 '10 at 10:09
  • I not sure I have the experience to state that but everything looks ok: – cheesemp Dec 02 '10 at 10:20
  • @cheesemp: Looks very interesting. Where are all the imports from? Doesn't look like you have anything from which it could import stuff. – Octavian Helm Dec 02 '10 at 10:28
  • Just noticed that the AndEngine wasn't on the export list. I've added it but no effect. Should the Android 2.1 lib also be? – cheesemp Dec 02 '10 at 10:29
  • @Octavian - The AndEngine is a separate project and is marked so in the Java Build Path in Eclipse. – cheesemp Dec 02 '10 at 10:31
  • Its still not fixed but I've marked Octavian's answer as accept because of the effort he's taken to fix the problem. I also think he's probably right in part. – cheesemp Dec 03 '10 at 21:00
2

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

vamsu
  • 1,439
  • 1
  • 9
  • 2