一个项目中的类强制转换异常而不是其他项目

时间:2013-12-10 18:15:59

标签: android google-cloud-messaging classcastexception

我关注GCM Tutorial并且我非常谨慎地在我的项目中犯了错误并实现相同的代码。但是当我运行项目时,我得到ClassCast异常。我以为我会错过一些东西,所以我从那篇文章下载了源代码并在我的项目中仔细复制了每一行,但我仍然得到同样的例外。请帮忙解决错误。

12-10 23:41:25.812: E/AndroidRuntime(9549): FATAL EXCEPTION: main
12-10 23:41:25.812: E/AndroidRuntime(9549): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.exaple.oldgcm/com.exaple.oldgcm.MainActivity}: java.lang.ClassCastException: android.app.Application cannot be cast to com.exaple.oldgcm.Controller
12-10 23:41:25.812: E/AndroidRuntime(9549):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
12-10 23:41:25.812: E/AndroidRuntime(9549):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
12-10 23:41:25.812: E/AndroidRuntime(9549):     at android.app.ActivityThread.access$600(ActivityThread.java:128)
12-10 23:41:25.812: E/AndroidRuntime(9549):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
12-10 23:41:25.812: E/AndroidRuntime(9549):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-10 23:41:25.812: E/AndroidRuntime(9549):     at android.os.Looper.loop(Looper.java:137)
12-10 23:41:25.812: E/AndroidRuntime(9549):     at android.app.ActivityThread.main(ActivityThread.java:4517)
12-10 23:41:25.812: E/AndroidRuntime(9549):     at java.lang.reflect.Method.invokeNative(Native Method)
12-10 23:41:25.812: E/AndroidRuntime(9549):     at java.lang.reflect.Method.invoke(Method.java:511)
12-10 23:41:25.812: E/AndroidRuntime(9549):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
12-10 23:41:25.812: E/AndroidRuntime(9549):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
12-10 23:41:25.812: E/AndroidRuntime(9549):     at dalvik.system.NativeStart.main(Native Method)
12-10 23:41:25.812: E/AndroidRuntime(9549): Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to com.exaple.oldgcm.Controller
12-10 23:41:25.812: E/AndroidRuntime(9549):     at com.exaple.oldgcm.MainActivity.onCreate(MainActivity.java:33)
12-10 23:41:25.812: E/AndroidRuntime(9549):     at android.app.Activity.performCreate(Activity.java:4470)
12-10 23:41:25.812: E/AndroidRuntime(9549):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
12-10 23:41:25.812: E/AndroidRuntime(9549):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
12-10 23:41:25.812: E/AndroidRuntime(9549):     ... 11 more

1 个答案:

答案 0 :(得分:0)

我认为问题在于您没有在清单中设置应用程序名称。

参考此解决方案:

android classcastexception at android.app.Application