10

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("\nMessage : ");
     // 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..

fadli wdt
  • 101
  • 1
  • 1
  • 5

9 Answers9

13

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

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    com.android.GPS21.SmsReceiver is the class which onReceiver located. I think that's not the problem.. – fadli wdt Jan 08 '11 at 18:27
  • @fadli wdt: I am telling you that this is what your error says. If that is not your error, then we cannot help you. Though I should point out that you will get the same error message -- I think -- if you are missing the superclass (e.g., your superclass for `com.android.GPS21.SmsReceiver` cannot be found). Also, since you do not work for Google, please do not use the `com.android` namespace. Use one based on a domain name you own. – CommonsWare Jan 08 '11 at 18:35
  • Sorry for namespace. I just follow the tutorial said. – fadli wdt Jan 13 '11 at 19:02
  • Note that even if your project contains a `com.android.GPS21.SmsReceiver`, that class must also extend `BroadcastReceiver`. If you have defined `onReceive`, for example, but do not declare it as an `@Override` (without extending) you won't get an error, but you will get the above exception at runtime. – Michael Jun 01 '13 at 03:53
5

This is an old question and I'm not sure that this was your trouble, but I just had this issue. Within Eclipse, I created the folder (really a package) in the wrong place. For example

Incorrect

enter image description here

The reason this is incorrect is that the Broadcast folder/package isn't within the namespace like you expect. This happens if you right click on My Program/src and create the package there. Notice that it is My Program/src/Broadcast which is what is wrong.

The reason is that the SmsReceiver class isn't in your namespace. In this case you may have something like this in your manifest.

<receiver android:name=".Broadcast.SmsReceiver">
    <intent-filter>
        <action android:name="android.provider.Telephony.SMS_RECEIVED" />
    </intent-filter>
</receiver>

When this is triggered, the SmsReceiver class is NOT found and you'll get the error.

Correct

enter image description here

The correct way to do this, and get the package in the proper namespace is to right click on com.example.my.program and create it there instead. Notice that it is My Program/src/com.example.my.program.Broadcast which is now correctly in the same namespace.

This will be found in by the app with the same manifest code above.

Kirk
  • 16,182
  • 20
  • 80
  • 112
  • 1
    I know that it has been a while since this was posted, but I wanted to thank @Kirk for the detail. Due to it's thoroughness, it helped me resolve my own issue. – AndroidDev Sep 07 '13 at 04:27
4

Your broadcastReceiver class must be a public class by example

public class ReceptorLlamadas extends BroadcastReceiver

red_neo
  • 41
  • 1
2

You have to write the complete path to your broadcastReceiver, I mean, if in your manifest file you jave package="com.myapp", but your MySmsBroadcast.java is not exactly under myapp package (it's on myapp.smsStuff.MySmsBroadcast, for example), in the

lrr
  • 21
  • 1
1

I had the same problem as well. In my case, my Virtual Device was corrupted.

Try creating a new one and running with it. Worked for me!

Ben Ripley
  • 2,115
  • 21
  • 33
1

you can write the receiver as "static". In the program my.sample, should write receiver " static SimpleSmsReceiver

jone
  • 11
  • 1
1

Provide fully qualified class name, That worked for me

Like this : *

<receiver android:name="com.zolipe.communitycensus.util.CensusReceiver">
     <intent-filter>
          <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
          <action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
     </intent-filter>
</receiver>

*

Naveen Kumar
  • 31
  • 10
0

Make sure you have a public constructor without parameters. For example I have my own BroadcastReceiver implementation that receives some properties on the constructor. After I added a public default (without parameters) constructor, it works perfectly.

0

I've got a same error. After I modified the "AndroidManifest.xml" like this, the error is resolved.

receiver android:name=".SimpleSmsReceiver"

->

receiver android:name=".SimpleSMSReceiver"

The error was like this.

...
01-13 10:23:10.787: ERROR/AndroidRuntime(378): java.lang.RuntimeException: Unable to instantiate receiver my.sample.SimpleSmsReceiver: java.lang.ClassNotFoundException: my.sample.SimpleSmsReceiver in loader dalvik.system.PathClassLoader[/data/app/my.sample-2.apk]
01-13 10:23:10.787: ERROR/AndroidRuntime(378):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2789)
01-13 10:23:10.787: ERROR/AndroidRuntime(378):     at android.app.ActivityThread.access$3200(ActivityThread.java:125)
01-13 10:23:10.787: ERROR/AndroidRuntime(378):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
bool.dev
  • 17,508
  • 5
  • 69
  • 93
user573566
  • 509
  • 2
  • 6
  • 9