App crashes on sendText method <p>I am developing my first android app where someone can send multiple sms to a designated number. The app used to run fine when I had the number and number of messages to be sent already programmed into the code. However, I created a separate activity where one can input the destination number and number of messages to be sent, and transfer that data back to the first activity through an intent. But now the app crashes upon attempting to send a message.</p> <p>Here is the first activity: </p> <pre><code>public class TextMessages extends AppCompatActivity { public static final String DEFAULT = "No Number Found"; private EditText customMessage; String gotNum; FloatingActionButton button; int request_code; String realnum; int temp; int recode; Button butt; int number; String num; String text; int x; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_text_messages); request_code = 1; FloatingActionButton button = (FloatingActionButton) findViewById(R.id.but); assert button != null; button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(TextMessages.this,Settings.class); startActivityForResult(intent, request_code); Intent a = new Intent(TextMessages.this,Settings.class); startActivityForResult(a, recode); } }); customMessage = (EditText)findViewById(R.id.customMessage); } public void onActivityResult(int requestCode, int resultCode, Intent data){ if (requestCode== request_code){ if (resultCode== Activity.RESULT_OK){ num = data.getStringExtra("value"); text = data.getStringExtra("cost"); } } } public void sendText(View view) { String message = ""; if (view.getId() == R.id.fab) { message = customMessage.getText().toString(); } else { Button sender = (Button)view; message = sender.getText().toString(); } //Toast.makeText(this, "Test", Toast.LENGTH_SHORT).show(); int i; x = Integer.parseInt(text); for (i = 0; i &lt; x; i++){ SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(num, null, message, null, null); } }} </code></pre> <p>As you can see I have replaced the predetermined number with String num and the number of messages to be sent with int x, which causes the app to crash when the button to send the messages is pressed.</p> <p>Here is the activity where the number and messages to be sent is collected from:</p> <pre><code>public class Settings extends AppCompatActivity { public EditText phoneNum; public Button apply; public EditText msgCounter; public Button save; int msgCount; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); phoneNum = (EditText)findViewById(R.id.phoneNum); msgCounter = (EditText)findViewById(R.id.msgCount); apply = (Button)findViewById(R.id.butto); save = (Button)findViewById(R.id.butt); save.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent pass = new Intent(); pass.putExtra("value", phoneNum.getText().toString()); pass.putExtra("cost",msgCounter.getText().toString()); setResult(Activity.RESULT_OK,pass); finish(); } }); } public void OnButtonClickedApply(View view) { String num; num = phoneNum.getText().toString(); //Toast.makeText(this, num, Toast.LENGTH_SHORT).show(); } public void saveMsg(View view) { msgCount = Integer.parseInt(msgCounter.getText().toString()); } } </code></pre> <p>Also I may add, when inputting data into the second activity. Upon pressing the button to save the data, the activity resets(reloads?) and I have to put the data in a second time, when pressing the button will then take me back to the first activity like it should.</p> <p>Crash Log: </p> <pre><code>06-27 19:14:55.583 2404-2404/com.linfirmware.emergencytext E/AndroidRuntime: FATAL EXCEPTION: main Process: com.linfirmware.emergencytext, PID: 2404 java.lang.IllegalStateException: Could not execute method for android:onClick at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293) at android.view.View.performClick(View.java:5198) at android.view.View$PerformClick.run(View.java:21147) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) at android.view.View.performClick(View.java:5198) at android.view.View$PerformClick.run(View.java:21147) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.SecurityException: Sending SMS message: uid 10057 does not have android.permission.SEND_SMS. at android.os.Parcel.readException(Parcel.java:1599) at android.os.Parcel.readException(Parcel.java:1552) at com.android.internal.telephony.ISms$Stub$Proxy.sendTextForSubscriber(ISms.java:768) at android.telephony.SmsManager.sendTextMessageInternal(SmsManager.java:310) at android.telephony.SmsManager.sendTextMessage(SmsManager.java:293) at com.example.rahul.customtext.TextMessages.sendText(TextMessages.java:94) at java.lang.reflect.Method.invoke(Native Method) at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) at android.view.View.performClick(View.java:5198) at android.view.View$PerformClick.run(View.java:21147) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 06-27 19:14:57.765 2404-2404/com.linfirmware.emergencytext I/Process: Sending signal. PID: 2404 SIG: 9 </code></pre> <p>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="com.example.rahul.customtext"&gt; &lt;uses-permission android:name="android.permission.SEND_SMS" /&gt; &lt;application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"&gt; &lt;activity android:name=".TextMessages"&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;activity android:name=".Settings" 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.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre>