gpt4 book ai didi

java - android - classnotfoundException - 神秘

转载 作者:行者123 更新时间:2023-12-01 12:47:01 26 4
gpt4 key购买 nike

我正在尝试了解 GCM 的工作原理。为此,我复制/粘贴 http://developer.android.com/ 的代码在“实现 GCM 客户端”部分中提出。

从服务器发送消息是可行的,但是当我的客户端应用程序收到消息时,它崩溃了,告诉我有一个:

E/AndroidRuntime(5722): java.lang.RuntimeException: Unable to instantiate receiver
com.test.testnotification3.GcmBroadcastReceiver: java.lang.ClassNotFoundException: Didn't
find class "com.test.testnotification3.GcmBroadcastReceiver" on path:
/data/app/com.test.testnotification3-2.apk

我在互联网上搜索了类似的问题,很多人似乎因为 list 中的问题而出现此错误( list 中的包名称错误)。但我检查了我的 list ,似乎没问题:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.testnotification3"
android:versionCode="1"
android:versionName="1.0" >

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.test.testnotification3.permission.C2D_MESSAGE" />

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<receiver
android:name="com.test.testnotification3.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />

<category android:name="com.test.testnotification3" />
</intent-filter>
</receiver>

<service android:name="com.test.testnotification3.GcmIntentService" />

<activity
android:name="com.test.testnotification3.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

如果你有什么想法...非常感谢!

编辑:这是我的 GcmBroadcastReceiver :

package core;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Explicitly specify that GcmIntentService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(),
GcmIntentService.class.getName());
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}

}

当然,由于包名称发生了变化,我将接收器的“com.test.testnotification3”替换为“core”。

最佳答案

您必须将接收器放入另一个包裹中。如果它位于主包上,系统将无法实例化它。

关于java - android - classnotfoundException - 神秘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24597041/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com