title: Android App to call a number on button click
body: <p>I want to call a number given in a textbox but I'm getting the error:</p>
  
  <blockquote>
    <p>The application 'xyz'(process com.android) has stopped unexpectedly</p>
  </blockquote>
  
  <p>The following is my code.  Where is it going wrong?</p>
  
  <pre><code>EditText txtPhn;
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      Button callButton = (Button)findViewById(R.id.btnCall);
      txtPhn = (EditText)findViewById(R.id.txtPhnNumber);
      callButton.setOnClickListener(new OnClickListener() {
  
          public void onClick(View v) {
              try {
                      Intent callIntent = new Intent(Intent.ACTION_CALL);
                      callIntent.setData(Uri.parse("tel:"+txtPhn.getText().toString()));
                      startActivity(callIntent);
                  } catch (ActivityNotFoundException activityException) {
                      Log.e("Calling a Phone Number", "Call failed", activityException);
                  }
          }
      });
  }
  </code></pre>
  
  <p><strong>EDITED</strong> LogCat</p>
  
  <pre><code>03-09 11:23:25.874: ERROR/AndroidRuntime(370): FATAL EXCEPTION: main
  03-09 11:23:25.874: ERROR/AndroidRuntime(370): java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:xxx-xxx-xxxx flg=0x10000000 cmp=com.android.phone/.OutgoingCallBroadcaster } from ProcessRecord{40738d70 370:org.krish.android/10034} (pid=370, uid=10034) requires android.permission.CALL_PHONE
  03-09 11:23:25.874: ERROR/AndroidRuntime(370):     at android.os.Parcel.readException(Parcel.java:1322)
  03-09 11:23:25.874: ERROR/AndroidRuntime(370):     at android.os.Parcel.readException(Parcel.java:1276)
  03-09 11:23:25.874: ERROR/AndroidRuntime(370):     at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1351)
  03-09 11:23:25.874: ERROR/AndroidRuntime(370):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1374)
  03-09 11:23:25.874: ERROR/AndroidRuntime(370):     at android.app.Activity.startActivityForResult(Activity.java:2827)
  03-09 11:23:25.874: ERROR/AndroidRuntime(370):     at android.app.Activity.startActivity(Activity.java:2933)
  03-09 11:23:25.874: ERROR/AndroidRuntime(370):     at org.krish.android.caller$1.onClick(caller.java:29)
  03-09 11:23:25.874: ERROR/AndroidRuntime(370):     at android.view.View.performClick(View.java:2485)
  03-09 11:23:25.874: ERROR/AndroidRuntime(370):     at android.view.View$PerformClick.run(View.java:9080)
  03-09 11:23:25.874: ERROR/AndroidRuntime(370):     at android.os.Handler.handleCallback(Handler.java:587)
  03-09 11:23:25.874: ERROR/AndroidRuntime(370):     at android.os.Handler.dispatchMessage(Handler.java:92)
  03-09 11:23:25.874: ERROR/AndroidRuntime(370):     at android.os.Looper.loop(Looper.java:123)
  03-09 11:23:25.874: ERROR/AndroidRuntime(370):     at android.app.ActivityThread.main(ActivityThread.java:3683)
  03-09 11:23:25.874: ERROR/AndroidRuntime(370):     at java.lang.reflect.Method.invokeNative(Native Method)
  03-09 11:23:25.874: ERROR/AndroidRuntime(370):     at    java.lang.reflect.Method.invoke(Method.java:507)
  03-09 11:23:25.874: ERROR/AndroidRuntime(370):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  03-09 11:23:25.874: ERROR/AndroidRuntime(370):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  03-09 11:23:25.874: ERROR/AndroidRuntime(370):     at dalvik.system.NativeStart.main(Native Method)`enter code here`
  </code></pre>