Reputation: 1266
I'm developing an android application and as soon as the AVD opens and I unlock the device and click the menu, I get an "Application stops unexpectedly" error. The following is my logcat log.
02-22 11:34:38.220: D/AndroidRuntime(336): Shutting down VM
02-22 11:34:38.220: W/dalvikvm(336): threadid=1: thread exiting with uncaught exception (group=0x40015560)
02-22 11:34:38.290: E/AndroidRuntime(336): FATAL EXCEPTION: main
02-22 11:34:38.290: E/AndroidRuntime(336): java.lang.RuntimeException: Unable to instantiate application com.compliment.ComplimentGenerator: java.lang.ClassCastException: com.compliment.ComplimentGenerator
02-22 11:34:38.290: E/AndroidRuntime(336): at android.app.LoadedApk.makeApplication(LoadedApk.java:466)
02-22 11:34:38.290: E/AndroidRuntime(336): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3260)
02-22 11:34:38.290: E/AndroidRuntime(336): at android.app.ActivityThread.access$2200(ActivityThread.java:117)
02-22 11:34:38.290: E/AndroidRuntime(336): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:969)
02-22 11:34:38.290: E/AndroidRuntime(336): at android.os.Handler.dispatchMessage(Handler.java:99)
02-22 11:34:38.290: E/AndroidRuntime(336): at android.os.Looper.loop(Looper.java:123)
02-22 11:34:38.290: E/AndroidRuntime(336): at android.app.ActivityThread.main(ActivityThread.java:3683)
02-22 11:34:38.290: E/AndroidRuntime(336): at java.lang.reflect.Method.invokeNative(Native Method)
02-22 11:34:38.290: E/AndroidRuntime(336): at java.lang.reflect.Method.invoke(Method.java:507)
02-22 11:34:38.290: E/AndroidRuntime(336): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-22 11:34:38.290: E/AndroidRuntime(336): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-22 11:34:38.290: E/AndroidRuntime(336): at dalvik.system.NativeStart.main(Native Method)
02-22 11:34:38.290: E/AndroidRuntime(336): Caused by: java.lang.ClassCastException: com.compliment.ComplimentGenerator
02-22 11:34:38.290: E/AndroidRuntime(336): at android.app.Instrumentation.newApplication(Instrumentation.java:957)
02-22 11:34:38.290: E/AndroidRuntime(336): at android.app.Instrumentation.newApplication(Instrumentation.java:942)
02-22 11:34:38.290: E/AndroidRuntime(336): at android.app.LoadedApk.makeApplication(LoadedApk.java:461)
02-22 11:34:38.290: E/AndroidRuntime(336): ... 11 more
EDIT: code available here: http://pastebin.com/VSvWvgGa
EDIT2: XML available here: http://pastebin.com/uGLpyUcW
EDIT3: After making the initial changes Druv recommended, I'm getting new logcat errors and I've updated my post with those errors
EDIT4: R.layout.main.xml: http://pastebin.com/Qe8Bx47m
Upvotes: 0
Views: 1617
Reputation: 9182
Could you add com.compliment over here:
<activity android:name="com.compliment.ComplimentGenerator" android:label="ComplimentGenerator">
Edit:
Change <activity android:name="ComplimentGenerator" android:label="ComplimentGenerator">
to <activity android:icon="@drawable/icon" android:label="ComplimentGenerator">
From the docs,
public class Application
Base class for those who need to maintain global application state. You can provide your own implementation by specifying its name in your AndroidManifest.xml's tag, which will cause that class to be instantiated for you when the process for your application/package is created.
There is normally no need to subclass Application. In most situation, static singletons can provide the same functionality in a more modular way. If your singleton needs a global context (for example to register broadcast receivers), the function to retrieve it can be given a Context which internally uses Context.getApplicationContext() when first constructing the singleton.
In other words, when you added android:name, the ComplimentGenerator class was being instantiated. However, ComplimentGenerator was not subclassing Application (which was required), which resulted in a ClassCastException.
Upvotes: 1
Reputation: 40416
AndroidManifest.xml
<application android:name="ComplimentGenerator" android:icon="@drawable/icon">
Just Rename Your
android:name="ComplimentGenerator" to android:label="ComplimentGenerator"
Upvotes: 3
Reputation: 2101
I think the "android:name" attribute value is wrong! Use the following (starting with the "."):
<activity android:name=".ComplimentGenerator" android:label="ComplimentGenerator">
Thus, Android will know the starting activity is com.compliment.ComplimentGenerator
"com.compliment" comes from the "package" attribute value
".ComplimentGenerator" comes from the "android:name" attribute value
Upvotes: 1