我正在尝试从我的 android 模拟器中检索我的 GCM 注册 ID,但是当我调试程序崩溃时。这是我的 MainActivity 代码:
try {
GCMRegistrar.checkDevice(this); // <-- Crashes here
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals(""))
{
GCMRegistrar.register(this,Sender_ID);
}
else
{
Log.v("Registrationnnnnn", "Already registered");
}
}
catch(Exception e)
{
Log.e("ErrorHAi",e.getMessage());
}
我读过这行检查设备是否支持 GCM。但我已经从 SDK Manager 附加功能安装了 Google Cloud Messaging。我也安装了
Android SDK 工具:第 20
版 Android SDK 平台工具:第 12
版 Android 4.1 Api 16
当我提到
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" />
这在我的清单文件中运行,但正如我在上面的代码中提到的那样崩溃。但是如果我将 targetSdkVersion 更改为 xx,如此处所述,它会显示 Install_Failed_OLDER_SDK。
我目前在 Android 4.1 API 级别 16 上运行此应用程序。
更新:
我的日志猫:
07-03 20:34:25.878: E/Trace(906): error opening trace file: No such file or directory (2)
07-03 22:30:57.748: E/Trace(1016): error opening trace file: No such file or directory (2)
07-03 22:31:01.998: E/AndroidRuntime(1016): FATAL EXCEPTION: main
07-03 22:31:01.998: E/AndroidRuntime(1016): java.lang.RuntimeException: Unable to instantiate receiver com.pack.gcm.MyBroadcastReceiver: java.lang.ClassNotFoundException: com.pack.gcm.MyBroadcastReceiver
07-03 22:31:01.998: E/AndroidRuntime(1016): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2210)
07-03 22:31:01.998: E/AndroidRuntime(1016): at android.app.ActivityThread.access$1500(ActivityThread.java:130)
07-03 22:31:01.998: E/AndroidRuntime(1016): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1271)
07-03 22:31:01.998: E/AndroidRuntime(1016): at android.os.Handler.dispatchMessage(Handler.java:99)
07-03 22:31:01.998: E/AndroidRuntime(1016): at android.os.Looper.loop(Looper.java:137)
07-03 22:31:01.998: E/AndroidRuntime(1016): at android.app.ActivityThread.main(ActivityThread.java:4745)
07-03 22:31:01.998: E/AndroidRuntime(1016): at java.lang.reflect.Method.invokeNative(Native Method)
07-03 22:31:01.998: E/AndroidRuntime(1016): at java.lang.reflect.Method.invoke(Method.java:511)
07-03 22:31:01.998: E/AndroidRuntime(1016): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-03 22:31:01.998: E/AndroidRuntime(1016): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-03 22:31:01.998: E/AndroidRuntime(1016): at dalvik.system.NativeStart.main(Native Method)
07-03 22:31:01.998: E/AndroidRuntime(1016): Caused by: java.lang.ClassNotFoundException: com.pack.gcm.MyBroadcastReceiver
07-03 22:31:01.998: E/AndroidRuntime(1016): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
07-03 22:31:01.998: E/AndroidRuntime(1016): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-03 22:31:01.998: E/AndroidRuntime(1016): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-03 22:31:01.998: E/AndroidRuntime(1016): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2205)
07-03 22:31:01.998: E/AndroidRuntime(1016): ... 10 more
现在我不知道为什么它会给出这样的错误,尽管我已经安装了所有的先决条件。