Android:无法实例化 C2DMBaseReceiver
我直接将所有三个 C2DM 类从 Google Code 的 ChomeToPhone 扩展复制到我的项目中 (http://code.google.com/p/chrometophone/.../c2dm),然后修改我的按照 Android 云到设备消息传递框架页面上的说明进行清单。当我运行我的程序时,出现以下错误。我不明白发生了什么或为什么:
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
I directly copied all three C2DM classes into my project from Google Code's ChomeToPhone extension (http://code.google.com/p/chrometophone/.../c2dm), and then modified my Manifest per the instructions on the Android Cloud to Device Messaging Framework page. When I run my program, I get the following error. I can't figure out what's going on or why:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
C2DMBaseReceiver
是一个抽象类,您无法实例化它。您应该子类化C2DMBaseReceiver
并提供您自己的实现。然后在清单中注册该类。请注意,您应该将该类放在包的根目录中。C2DMBaseReceiver
is an abstract class, you can't instantiate it. You should subclassC2DMBaseReceiver
and provide your own implementation. Then register that class in your manifest. Note that you should put that class in the root of your package.C2DMBaseReceiver是抽象类:
public Abstract class C2DMBaseReceiver extends IntentService{...}
抽象类无法实例化,但可以进行子类化。
C2DMBaseReceiver is abstract class:
public abstract class C2DMBaseReceiver extends IntentService{...}
Abstract classes cannot be instantiated, but they can be subclassed.