java.lang.RuntimeException:无法实例化服务com.google.android.gcm.GCMBroadCastReceiver [英] java.lang.RuntimeException: Unable to instantiate service com.google.android.gcm.GCMBroadCastReceiver

查看:106
本文介绍了java.lang.RuntimeException:无法实例化服务com.google.android.gcm.GCMBroadCastReceiver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个android应用程序.

I am developing an android App.

我正在通过GCM实施推送通知.

I am implementing push notification with GCM.

但是,我无法从服务器接收推送通知.错误日志如下.

However, I cannot receive push notification from my server. The error log says below.

java.lang.RuntimeException: Unable to instantiate service
com.google.android.gcm.GCMBroadCastReceiver: java.lang.ClassNotFoundException: 
Didn't find class "com.google.android.gcm.GCMBroadCastReceiver" on path: DexPathList

AndroidManifest.xml在下面.

AndroidManifest.xml is below.

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

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="net.myapp.permission.RECEIVE" />

    <permission
        android:name="net.myapp.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="net.myapp.permission.C2D_MESSAGE" />

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="21" />

    <application
        android:name="net.myapp.sub.AppController"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/app_id" />

        <activity
            android:name="net.myapp.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>
        <activity
            android:name="net.myapp.DetailActivity"
            android:uiOptions="splitActionBarWhenNarrow" >
            <meta-data
                android:name="android.support.UI_OPTIONS"
                android:value="splitActionBarWhenNarrow" />

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="twittercallback" />
            </intent-filter>
        </activity>

        <receiver
            android:name="com.google.android.gcm.GCMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="net.myapp" />
            </intent-filter>
        </receiver>

        <service android:name=".GcmIntentService" />

    </application>

</manifest>

GcmBroadcastReceiver.java在下面.

GcmBroadcastReceiver.java is below.

package net.myapp;

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) {

        ComponentName comp = new ComponentName(context.getPackageName(),
                 GcmIntentService.class.getName());

        startWakefulService(context, (intent.setComponent(comp)));
        setResultCode(Activity.RESULT_OK);
    }

}

我确认我已正确导入android-support-v4.jar和google-play-services.jar. 我尝试了Google搜索提供的一些解决方案,但是还无法解决.

I confirm that I properly import android-support-v4.jar and google-play-services.jar. I tried some solutions from Google Search, however, I cannot solve yet.

您能告诉我如何解决上述问题吗?

Could you tell me how to solve the above problem?

推荐答案

在清单中,您写道:

android:name="com.google.android.gcm.GCMBroadcastReceiver"

但是您的GcmBroadcastReceiver.java在软件包net.myapp

android:name="com.google.android.gcm.GCMBroadcastReceiver"更改为android:name="net.myapp.GcmBroadcastReceiver"

这篇关于java.lang.RuntimeException:无法实例化服务com.google.android.gcm.GCMBroadCastReceiver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆