Android - 无法实例化接收器

时间:2015-04-09 19:48:25

标签: java android android-intent

使用广播时遇到此问题。使用BroadcastReceiver时会发生错误。

以下是代码:

<receiver
        android:name="com.org.ti.lucky.gcm.GcmBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>

            <!-- Receives the actual messages. -->
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />

            <category android:name="com.org.ti.lucky.gcm" />
        </intent-filter>
    </receiver>

    <service android:name="com.org.ti.lucky.gcm.GcmIntentService" />

这是类和错误:

package com.org.ti.lucky.gcm;

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);
    }
}

这是logcat输出:

04-09 14:38:09.899: E/AndroidRuntime(2103): FATAL EXCEPTION: main
04-09 14:38:09.899: E/AndroidRuntime(2103): java.lang.RuntimeException: Unable to instantiate receiver com.org.ti.lucky.gcm.GcmBroadcastReceiver: java.lang.ClassNotFoundException: com.org.ti.lucky.gcm.GcmBroadcastReceiver
04-09 14:38:09.899: E/AndroidRuntime(2103):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2210)
04-09 14:38:09.899: E/AndroidRuntime(2103):     at android.app.ActivityThread.access$1500(ActivityThread.java:130)
04-09 14:38:09.899: E/AndroidRuntime(2103):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1271)
04-09 14:38:09.899: E/AndroidRuntime(2103):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-09 14:38:09.899: E/AndroidRuntime(2103):     at android.os.Looper.loop(Looper.java:137)
04-09 14:38:09.899: E/AndroidRuntime(2103):     at android.app.ActivityThread.main(ActivityThread.java:4745)
04-09 14:38:09.899: E/AndroidRuntime(2103):     at java.lang.reflect.Method.invokeNative(Native Method)
04-09 14:38:09.899: E/AndroidRuntime(2103):     at java.lang.reflect.Method.invoke(Method.java:511)
04-09 14:38:09.899: E/AndroidRuntime(2103):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-09 14:38:09.899: E/AndroidRuntime(2103):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-09 14:38:09.899: E/AndroidRuntime(2103):     at dalvik.system.NativeStart.main(Native Method)
04-09 14:38:09.899: E/AndroidRuntime(2103): Caused by: java.lang.ClassNotFoundException: com.org.ti.lucky.gcm.GcmBroadcastReceiver
04-09 14:38:09.899: E/AndroidRuntime(2103):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
04-09 14:38:09.899: E/AndroidRuntime(2103):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-09 14:38:09.899: E/AndroidRuntime(2103):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-09 14:38:09.899: E/AndroidRuntime(2103):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2205)
04-09 14:38:09.899: E/AndroidRuntime(2103):     ... 10 more

0 个答案:

没有答案