我直接将这三个c2dm类从google code的chometophone扩展(http://code.google.com/p/chrometophone/.../c2dm)复制到我的项目中,然后按照Android Cloud to Device Messaging Framework页面上的说明修改我的清单。当我运行我的程序时,我得到以下错误。我不知道发生了什么事,也不知道为什么:
06-12 18:50:43.243: ERROR/AndroidRuntime(923): FATAL EXCEPTION: main
06-12 18:50:43.243: ERROR/AndroidRuntime(923): java.lang.RuntimeException: Unable to instantiate receiver com.name.asdf.C2DMBaseReceiver: java.lang.InstantiationException: com.name.asdf.C2DMBaseReceiver
06-12 18:50:43.243: ERROR/AndroidRuntime(923): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2789)
06-12 18:50:43.243: ERROR/AndroidRuntime(923): at android.app.ActivityThread.access$3200(ActivityThread.java:125)
06-12 18:50:43.243: ERROR/AndroidRuntime(923): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
06-12 18:50:43.243: ERROR/AndroidRuntime(923): at android.os.Handler.dispatchMessage(Handler.java:99)
06-12 18:50:43.243: ERROR/AndroidRuntime(923): at android.os.Looper.loop(Looper.java:123)
06-12 18:50:43.243: ERROR/AndroidRuntime(923): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-12 18:50:43.243: ERROR/AndroidRuntime(923): at java.lang.reflect.Method.invokeNative(Native Method)
06-12 18:50:43.243: ERROR/AndroidRuntime(923): at java.lang.reflect.Method.invoke(Method.java:521)
06-12 18:50:43.243: ERROR/AndroidRuntime(923): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-12 18:50:43.243: ERROR/AndroidRuntime(923): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-12 18:50:43.243: ERROR/AndroidRuntime(923): at dalvik.system.NativeStart.main(Native Method)
06-12 18:50:43.243: ERROR/AndroidRuntime(923): Caused by: java.lang.InstantiationException: com.name.asdf.C2DMBaseReceiver
06-12 18:50:43.243: ERROR/AndroidRuntime(923): at java.lang.Class.newInstanceImpl(Native Method)
06-12 18:50:43.243: ERROR/AndroidRuntime(923): at java.lang.Class.newInstance(Class.java:1429)
06-12 18:50:43.243: ERROR/AndroidRuntime(923): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2780)
06-12 18:50:43.243: ERROR/AndroidRuntime(923): ... 10 more
最佳答案
C2DMBaseReceiver
是一个抽象类,不能实例化它。您应该子类化C2DMBaseReceiver
并提供自己的实现。然后在您的清单中注册该类。注意,应该将该类放在包的根目录中。