Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to instantiate error?
    primarykey
    data
    text
    <p>Here is my source code.</p> <pre><code>public class MainActivity extends Activity { private static String content; private static String phone; private String number; private String message; private BroadcastReceiver receiver = new BroadcastReceiver(){ @Override public void onReceive(Context context, Intent intent) { //---get the SMS message passed in--- Bundle bundle = intent.getExtras(); SmsMessage[] msgs = null; if (bundle != null) { number = ""; message = ""; //---retrieve the SMS message received--- Object[] pdus = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int i=0; i&lt;msgs.length; i++){ msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]); number = msgs[i].getOriginatingAddress(); message = msgs[i].getMessageBody(); } //---display the new SMS message--- Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); SendMe(); } } }; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); IntentFilter filter = new IntentFilter(); registerReceiver(receiver, filter); setContentView(R.layout.main); } public void SendMe(){ PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(number, null, message, pi, null); } } </code></pre> <p>I keep getting this error in the logcat </p> <blockquote> <p>06-28 17:11:23.241: ERROR/AndroidRuntime(1311): java.lang.RuntimeException: Unable to instantiate receiver com.ftt.autospond.MainActivity: java.lang.ClassCastException: com.ftt.autospond.MainActivity</p> </blockquote> <p>Here is my manifest </p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; </code></pre> <p> </p> <pre><code>&lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt; &lt;activity android:name=".MainActivity" android:label="@string/app_name"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;receiver android:name="com.ftt.autospond.MainActivity"&gt; &lt;intent-filter&gt; &lt;action android:name= "android.provider.Telephony.SMS_RECEIVED" /&gt; </code></pre> <p> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload