08-31 02:00:14.733: E/AndroIDRuntime(30973): java.lang.RuntimeException: Unable to instantiate receiver com.example.smsmining.GcmbroadcastReceiver: java.lang.classNotFoundException: DIDn't find class "com.example.smsmining.GcmbroadcastReceiver" on path: DexPathList[[zip file "/data/app/com.example.smsmining-1.apk"],nativelibraryDirectorIEs=[/data/app-lib/com.example.smsmining-1,/vendor/lib,/system/lib]]08-31 02:00:14.733: E/AndroIDRuntime(30973): at androID.app.ActivityThread.handleReceiver(ActivityThread.java:2405)08-31 02:00:14.733: E/AndroIDRuntime(30973): at androID.app.ActivityThread.access00(ActivityThread.java:141)08-31 02:00:14.733: E/AndroIDRuntime(30973): at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1332)08-31 02:00:14.733: E/AndroIDRuntime(30973): at androID.os.Handler.dispatchMessage(Handler.java:99)08-31 02:00:14.733: E/AndroIDRuntime(30973): at androID.os.Looper.loop(Looper.java:137)08-31 02:00:14.733: E/AndroIDRuntime(30973): at androID.app.ActivityThread.main(ActivityThread.java:5103)08-31 02:00:14.733: E/AndroIDRuntime(30973): at java.lang.reflect.Method.invokeNative(Native Method)08-31 02:00:14.733: E/AndroIDRuntime(30973): at java.lang.reflect.Method.invoke(Method.java:525)08-31 02:00:14.733: E/AndroIDRuntime(30973): at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)08-31 02:00:14.733: E/AndroIDRuntime(30973): at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:553)08-31 02:00:14.733: E/AndroIDRuntime(30973): at dalvik.system.NativeStart.main(Native Method)08-31 02:00:14.733: E/AndroIDRuntime(30973): Caused by: java.lang.classNotFoundException: DIDn't find class "com.example.smsmining.GcmbroadcastReceiver" on path: DexPathList[[zip file "/data/app/com.example.smsmining-1.apk"],/system/lib]]08-31 02:00:14.733: E/AndroIDRuntime(30973): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)08-31 02:00:14.733: E/AndroIDRuntime(30973): at java.lang.classLoader.loadClass(ClassLoader.java:501)08-31 02:00:14.733: E/AndroIDRuntime(30973): at java.lang.classLoader.loadClass(ClassLoader.java:461)08-31 02:00:14.733: E/AndroIDRuntime(30973): at androID.app.ActivityThread.handleReceiver(ActivityThread.java:2400)08-31 02:00:14.733: E/AndroIDRuntime(30973): ... 10 more
我的清单文件:
<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID" package="com.example.smsmining" androID:versionCode="1" androID:versionname="1.0" > <uses-sdk androID:minSdkVersion="9" androID:targetSdkVersion="16" /> <uses-permission androID:name="androID.permission.READ_SMS"/> <uses-permission androID:name="androID.permission.RECEIVE_SMS"/> <uses-permission androID:name="androID.permission.READ_CONTACTS"/> <uses-permission androID:name="androID.permission.INTERNET"/> <uses-permission androID:name="androID.permission.GET_ACCOUNTS" /> <uses-permission androID:name="androID.permission.WAKE_LOCK" /> <permission androID:name="com.example.smsmining.permission.C2D_MESSAGE" androID:protectionLevel="signature" /> <uses-permission androID:name="com.example.smsmining.permission.C2D_MESSAGE" /> <!-- This app has permission to register and receive data message. --> <uses-permission androID:name="com.Google.androID.c2dm.permission.RECEIVE" /> <application androID:allowBackup="true" androID:icon="@drawable/ic_launcher" androID:label="@string/app_name" androID:theme="@style/Apptheme" > <activity androID:name=".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> <receiver androID:name="com.example.smsmining.SMSbroadcastReceiver"> <intent-filter> <action androID:name="androID.provIDer.Telephony.SMS_RECEIVED"/> </intent-filter> </receiver> <receiver androID:name=".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="com.example.smsmining" /> </intent-filter> </receiver> <service androID:name=".GCMIntentService" /> </application></manifest>
GcmbroadcastReceiver.java
package com.example.smsmining;import androID.app.Activity;import androID.content.Componentname;import androID.content.Context;import androID.content.Intent;import androID.support.v4.content.WakefulbroadcastReceiver;/** * This {@code WakefulbroadcastReceiver} takes care of creating and managing a * partial wake lock for your app. It passes off the work of processing the GCM * message to an {@code IntentService},while ensuring that the device does not * go back to sleep in the Transition. The {@code IntentService} calls * {@code GcmbroadcastReceiver.completeWakefulintent()} when it is ready to * release the wake lock. */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); }}
GcmIntentService.java
public class GcmIntentService extends IntentService { public static final int NOTIFICATION_ID = 1; private notificationmanager mnotificationmanager; NotificationCompat.Builder builder; public GcmIntentService() { super("GcmIntentService"); } public static final String TAG = "GCM Demo"; @OverrIDe protected voID onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your broadcastReceiver. String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /* * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types,just ignore any message types you're * not interested in,or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification("Deleted messages on server: " + extras.toString()); // If it's a regular GCM message,do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // This loop represents the service doing some work. for (int i = 0; i < 5; i++) { Log.i(TAG,"Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime()); try { Thread.sleep(5); } catch (InterruptedException e) { } } Log.i(TAG,"Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. sendNotification("Received: " + extras.toString()); Log.i(TAG,"Received: " + extras.toString()); } } // Release the wake lock provIDed by the WakefulbroadcastReceiver. GcmbroadcastReceiver.completeWakefulintent(intent); } // Put the message into a notification and post it. // This is just one simple example of what you might choose to do with // a GCM message. private voID sendNotification(String msg) { mnotificationmanager = (notificationmanager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this,new Intent(this,MainActivity.class),0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallicon(R.drawable.ic_launcher) .setContentTitle("GCM Notification") .setStyle(new NotificationCompat.BigTextStyle() .bigText(msg)) .setContentText(msg); mBuilder.setContentIntent(contentIntent); mnotificationmanager.notify(NOTIFICATION_ID,mBuilder.build()); }}解决方法 我有同样的错误.这对我有帮助.
尝试检查v.4库.
属性 – > Java构建路径 – >订单和导出
编辑:选择项目并转到:PropertIEs-> Java Build Path-> Order and Export,确保在列表中选中了androID.support.v4库,如果没有,请标记它. (我假设您已经将库导入到项目中),清理项目并且它应该可以工作
总结以上是内存溢出为你收集整理的android – Google Cloud Messaging(GCM) – 无法实例化接收器 – java.lang.ClassNotFoundException全部内容,希望文章能够帮你解决android – Google Cloud Messaging(GCM) – 无法实例化接收器 – java.lang.ClassNotFoundException所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)