ClassCastException starting Activity


Last Updated:

  1. jcrowley

    jcrowley New Member

    Recompiled a working app and now it will not install. Full LogCat attached, but basically it's throwing a ClassCastException while trying to instantiate the app. The source has not changed, and a week ago this compiled and installed with no problems.

    Compiling against version 2.2 and loading into a Droid also running 2.2

    The SDK was downloaded months ago and has not been changed, and as far as I know the Droid has not been updated.

    Did a complete clean and rebuild, no compile problems (working in Eclipse IDE). Assumed an environmental problem, so created a completely new Eclipse workspace, started a new Project, and imported all the code. Still get the same error.

    Beginning of the main routine is:

    Code (Text):
    1.  
    2. package com.screenpc;
    3.  
    4. /** MAIN routine for the ANDROID environment        */
    5. public class nimbus extends Activity
    6.                     implements nimbusI
    7. {
    The APK is in fact installed on the device, but throws this error on every attempt to start it.

    Any thoughts?

    Attached Files:


    Advertisement
  2. .If the code you're showing is really the top of your file, you're missing the nessessary
    Code (Text):
    1. import android.app.Activity;
    line, maybe you deleted it inadvertantly, I've done that.

    Also, your Activity sub-class isn't your main routine but a class the VM uses to instantiate your ui. The main looper is far out of view of mere users like you and I. That's part of the beauty of Android.
  3. jcrowley

    jcrowley New Member

    No, the code was just a portion -- the import is actually there. (And if it wasn't, the compile should have failed anyway.)

    Still very puzzling ....
  4. Code (Text):
    1.  
    2. 11-11 17:05:16.083: INFO/PackageManager(1105): /data/app/com.screenpc-2.apk changed; unpacking\par
    3. 11-11 17:05:16.083: INFO/PackageManager(1105): Package com.screenpc codePath changed from /data/app/com.screenpc-1.apk to /data/app/com.screenpc-2.apk; Retaining data and using new\par
    4. 11-11 17:05:16.091: DEBUG/installd(1016): DexInv: --- BEGIN '/data/app/com.screenpc-2.apk' ---\par
    5.  
    It looks here like you've got two versions of your .apk in there and the system is confused about which to use. You might try removing them all and re-installing.
  5. jcrowley

    jcrowley New Member

    Good eyes on the 2 versions .... had missed that.

    Used Settings -> Applications -> Manage Applications to uninstall the app. Uninstalled all other downloaded apps also to get back to a clean system. Still no joy though -- same abort. Do you think there is some junk left over after uninstalling? Any way to clean it out?

    Compiled with an explicit reference to the Activity:

    Code (Text):
    1. public class nimbus extents android.app.Activity ....
    2.  
    with same result (if there was an ambiguity, the compile should have failed anyway).

    It's got to be an environmental issue, but as far as I know there were no changes to the SDK on the development system since the app was installed successfully a couple of weeks ago.

    Where else can I look?

    BTW: It would be nice if the ClassCastException error displayed what class was expected vs what actual class is present. Since this abort occurs before the app even begins execution it's impossible to plug in any debug statements! Will see if I can bring up anything in debug or try it on the simulator.
  6. Any changes in the log ouput?

    Have you tried to remove the differing versions on the command line with pm?
    Code (Text):
    1.  
    2. adb shell
    3. pm list packages
    4.  
    should show you if your package is installed.
    Code (Text):
    1.  
    2. pm path your.apps.uri
    3.  
    will show the path(s?) to its environment. I will be curious to know if it shows both. I don't know how you will be able to remove the second yet, but it would seem that if you installed under a different uri (changed the name of your package) and your app ran correctly that would prove this is the problem.
  7. jcrowley

    jcrowley New Member

    May have found out what is happening.

    If you add the attribute android:name=xxxx to the <application ..> section of the AndroidManifest then the application ABORTS. If xxxx is the same as the android:name=... in the <activity ... > section, then you get a ClassCastException. If you put in a nonsense name, then it aborts with a ClassNotFound exception.

    Can anyone explain what is happening here? I can understand the ClassNotFound exception, but not the ClassCastException if both names are the same.

    Also, is there a rule that android:name can appear either in the <application ...> level or the <activity ....> level but not both? (And if there is, a compile-time warning would sure save a lot of time tracking down what appears to be an obscure error!).

    Thanks for any enlightenment that anyone can provide.

Share This Page