Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
260 views
in Technique[技术] by (71.8m points)

android - Unable to instantiate receiver in BroadcastReceiver SMS

Why I have this error :

ERROR/AndroidRuntime(854): Uncaught handler: thread main exiting due to uncaught exception
ERROR/AndroidRuntime(854): java.lang.RuntimeException: Unable to instantiate receiver com.android.GPS21.SmsReceiver: java.lang.ClassNotFoundException: com.android.GPS21.SmsReceiver in loader dalvik.system.PathClassLoader@43d02ef0
ERROR/AndroidRuntime(854): Caused by: java.lang.ClassNotFoundException: com.android.GPS21.SmsReceiver in loader dalvik.system.PathClassLoader@43d02ef0

This is my onReceive events:

public void onReceive(Context context, Intent intent) {
  // TODO Auto-generated method stub
  Log.i(LOG_TAG, "Recieved a message");
  if (intent.getAction().equals(ACTION)) {
   // if(message starts with SMStretcher recognize BYTE)
   StringBuilder sb = new StringBuilder();

   // The SMS-Messages are 'hiding' within the extras of the Intent.
   Bundle bundle = intent.getExtras();
   if (bundle != null) {

    // Get all messages contained in the Intent
    // Telephony.Sms.Intents.getMessagesFromIntent(intent) does not
    // work anymore hence the below changes

    Object[] pduObj = (Object[]) bundle.get("pdus");
    SmsMessage[] messages = new SmsMessage[pduObj.length];
    for (int i = 0; i < pduObj.length; i++)
     messages[i] = SmsMessage.createFromPdu((byte[]) pduObj[i]);
    // Feed the StringBuilder with all Messages found.
    for (SmsMessage currentMessage : messages) {
     sb.append("SMS Received From: ");
     // Sender-Number
     sb.append(currentMessage.getDisplayOriginatingAddress());
     sb.append("
Message : ");
     // Actual Message-Content
     sb.append(currentMessage.getDisplayMessageBody());
    }
   }
   // Logger Debug-Output
   Log.i(LOG_TAG, "[SMSApp] onReceive: " + sb);

   // Show the Notification containing the Message.
   Toast.makeText(context, sb.toString(), Toast.LENGTH_LONG).show();
  }

In debug that onReceive() is error.

I just make BroadcastReceiver to receive SMS and show in notification Toast..

And I try send SMS from DDMS and that error appear..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your manifest claims you have a class named com.android.GPS21.SmsReceiver, and Android cannot find it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...