title: Sending sms app inside a Fragment
body: <p>I'm creating an android using fragments .I have created a an sms fragment for sending sms to a specific number but when it runs well but when i type the message then press send , the app crashes and closes. help me out.</p>
  
  <pre><code>public class SMS extends Fragment {
  
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
  
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
  
          // View v = inflater.inflate(R.layout.fragment, null);
          View v = inflater.inflate(R.layout.sms, container, false);
          return v;
  
      }
  
  
      public void sendsms(View v)
      {
  
          //refernce the edittext
          EditText message=(EditText) v.findViewById(R.id.Messege);
          //get the phone the number and the message
  
          String number="0712345678";
          String msg=message.getText().toString();
          //use the sms manager to send message
          SmsManager sm=SmsManager.getDefault();
          sm.sendTextMessage(number, null, msg, null, null);
          Toast.makeText(getActivity(),"Messege sent",Toast.LENGTH_LONG).show();
  
  
      }
  
  
  }
  </code></pre>
  
  <p>the following is the xml layout that I have used.</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:orientation="vertical"
      android:background="@drawable/log"
      android:layout_height="match_parent"
     &gt;
  
      &lt;TextView
          android:id="@+id/textView1"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="Send your feedback" /&gt;
  
       &lt;EditText
          android:id="@+id/Messege"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true"
          android:hint="Enter your messege"
          android:layout_marginTop="15dp"
          android:ems="10" &gt;
  
  &lt;/EditText&gt;
  
       &lt;Button
           android:id="@+id/send"
           android:onClick="sendsms"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:text="Send SMS" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>