Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Application not running (Error : Application stopped running unexpectedly. Please Try Again)
    text
    copied!<p>This is the manifest file </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="net.learn2develop.SMSMessaging" android:versionCode="1" android:versionName="1.0"&gt; &lt;uses-sdk android:minSdkVersion="10" /&gt; &lt;uses-permission android:name="android.permission.SEND_SMS"&gt;&lt;/uses-permission&gt; &lt;uses-permission android:name="android.permission.RECEIVE_SMS"&gt;&lt;/uses-permission&gt; &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt; &lt;activity android:name=".SMS" 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;/application&gt; &lt;/manifest&gt; </code></pre> <p>This is the XML file (main.xml)</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Enter the phone number of recipient" /&gt; &lt;EditText android:id="@+id/txtPhoneNo" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Message" /&gt; &lt;EditText android:id="@+id/txtMessage" android:layout_width="fill_parent" android:layout_height="150px" android:gravity="top" /&gt; &lt;Button android:id="@+id/btnSendSMS" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Send SMS" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>This is the java file (SMS.java):-</p> <pre><code>package net.learn2develop.SMSMessaging; import android.app.Activity; import android.app.PendingIntent; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import android.telephony.SmsManager; public class SMS extends Activity { Button btnSendSMS; EditText txtPhoneNo; EditText txtMessage; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btnSendSMS = (Button) findViewById(R.id.btnSendSMS); txtPhoneNo = (EditText) findViewById(R.id.txtPhoneNo); txtMessage = (EditText) findViewById(R.id.txtMessage); btnSendSMS.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String phoneNo = txtPhoneNo.getText().toString(); String message = txtMessage.getText().toString(); if (phoneNo.length()&gt;0 &amp;&amp; message.length()&gt;0) { sendSMS(phoneNo, message); } else { Toast.makeText(getBaseContext(), "Please enter both phone number and message.", Toast.LENGTH_SHORT).show(); } } }); } private void sendSMS(String phoneNumber, String message) { PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, SMS.class), 0); SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, pi, null); } } </code></pre> <p>The error portion :-</p> <pre><code>08-26 23:06:41.040: ERROR/AndroidRuntime(411): FATAL EXCEPTION: main 08-26 23:06:41.040: ERROR/AndroidRuntime(411): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.learn2develop.SMSMessaging/net.learn2develop.SMSMessaging.SMS}: java.lang.NullPointerException 08-26 23:06:41.040: ERROR/AndroidRuntime(411): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 08-26 23:06:41.040: ERROR/AndroidRuntime(411): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 08-26 23:06:41.040: ERROR/AndroidRuntime(411): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 08-26 23:06:41.040: ERROR/AndroidRuntime(411): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 08-26 23:06:41.040: ERROR/AndroidRuntime(411): at android.os.Handler.dispatchMessage(Handler.java:99) 08-26 23:06:41.040: ERROR/AndroidRuntime(411): at android.os.Looper.loop(Looper.java:123) 08-26 23:06:41.040: ERROR/AndroidRuntime(411): at android.app.ActivityThread.main(ActivityThread.java:3683) 08-26 23:06:41.040: ERROR/AndroidRuntime(411): at java.lang.reflect.Method.invokeNative(Native Method) 08-26 23:06:41.040: ERROR/AndroidRuntime(411): at java.lang.reflect.Method.invoke(Method.java:507) 08-26 23:06:41.040: ERROR/AndroidRuntime(411): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 08-26 23:06:41.040: ERROR/AndroidRuntime(411): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 08-26 23:06:41.040: ERROR/AndroidRuntime(411): at dalvik.system.NativeStart.main(Native Method) 08-26 23:06:41.040: ERROR/AndroidRuntime(411): Caused by: java.lang.NullPointerException 08-26 23:06:41.040: ERROR/AndroidRuntime(411): at net.learn2develop.SMSMessaging.SMS.onCreate(SMS.java:31) 08-26 23:06:41.040: ERROR/AndroidRuntime(411): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 08-26 23:06:41.040: ERROR/AndroidRuntime(411): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 08-26 23:06:41.040: ERROR/AndroidRuntime(411): ... 11 more </code></pre>
 

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