views:

77

answers:

2

hello, i have a simple activity program in android. basically the class just extends Activity. But when i start it i get a ClassCastException in the constructor of my class. i dont even have a constructor defined, so it must be in the constructor of the superclass which is Activity.

unfortunately the debugger doesnt give any detailed information on what class it is trying to cast.

here is the stacktrace:

Thread [<1> main] (Suspended (exception RuntimeException))  
    ActivityThread$PackageInfo.makeApplication(boolean, Instrumentation) line: 649  
    ActivityThread.handleBindApplication(ActivityThread$AppBindData) line: 4232 
    ActivityThread.access$3000(ActivityThread, ActivityThread$AppBindData) line: 125    
    ActivityThread$H.handleMessage(Message) line: 2071  
    ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
    Looper.loop() line: 123 
    ActivityThread.main(String[]) line: 4627    
    Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
    Method.invoke(Object, Object...) line: 521  
    ZygoteInit$MethodAndArgsCaller.run() line: 868  
    ZygoteInit.main(String[]) line: 626 
    NativeStart.main(String[]) line: not available [native method]  

and when i look into this runtimeexception i get:

detailMessage "Unable to instantiate application com.test.MyApp: java.lang.ClassCastException: com.test.MyApp" (id=830067694464)

the only code is

package com.test;
import android.app.Activity;
public class MyApp extends Activity {

}

thanks for any help on this!

A: 

Post some code.

Bartinger
edit: i did post the code, but i dont think the cause is there, since it is crashing inside the android activity's constructor
clamp
maybe if you call the onCreate with the super.onCreate in it
Bartinger
i also tried this, but no difference
clamp
+1  A: 
  1. Open AndroidManifest.xml
  2. Find tag application
  3. Remove attribute android:name (if exists)
  4. Add attribute android:name="android.app.Application"

This is what I did and the problem had gone.

Maxim Kachurovskiy
thanks, but that doesnt help. do you really mean to set the string "android.app.Application" there or actually the name of the application?
clamp
edited the answer, hope it became more clear. Yes, I mean exactly "android.app.Application"
Maxim Kachurovskiy
thanks that did indeed fix the problem!
clamp