title: java Null pointer exception after onClick
body: <p>I am writing an app that sends an e-mail with multiple image as attachments. I followed this link : <a href="https://stackoverflow.com/questions/2264622/android-multiple-email-attachments-using-intent">Android multiple email attachments using Intent</a> to set up the Email intent and stuff .But the app force closes when I click on the send button and there seeems to be a Null Pointer Exception. </p>
  
  <p>Here's the code for the two classes that are involved (only for the email part) :</p>
  
  <p>PrevEmail.java :</p>
  
  <pre><code>   public class PrevEmail extends Activity{
  
  Context context;
  TextView tv,tvEmail,tvEmailAd,tvSubject,tvContent,tvLocation;
  EditText etSubject,etContent,etLocation;
  String subject,content,location;
  Button send;
  String btnSelected;
  String[] imgPath;
  Bundle extras;
  ArrayList&lt;Uri&gt; uris;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
      setContentView(R.layout.prevemail);
      intializeVar();
  }
  
  private void intializeVar() {
      // Links xml to java
      tv = (TextView) findViewById(R.id.tv);
      tvEmail = (TextView) findViewById(R.id.tvEmail);
      tvEmailAd = (TextView) findViewById(R.id.tvEmailAd);
      tvSubject = (TextView) findViewById(R.id.tvSubject);
      tvContent = (TextView) findViewById(R.id.tvContent);
      tvLocation = (TextView) findViewById(R.id.tvLocation);
  
      etSubject = (EditText) findViewById(R.id.Subject);
      etContent = (EditText) findViewById(R.id.Content);
      etLocation= (EditText) findViewById(R.id.Location);
  
      send = (Button) findViewById(R.id.bSend);
  
  
  
      extras = getIntent().getExtras();
      if(extras!=null){
          btnSelected=extras.getString("Button");
          imgPath=extras.getStringArray("Path");
  
          //Sets the E-mail field according to the value received by the Bundle.
          if(btnSelected.equalsIgnoreCase("case1")){
              tvEmailAd.setText("email_address");
          }else if(btnSelected.equalsIgnoreCase("case2")){
              tvEmailAd.setText("email_address");
          }else if(btnSelected.equalsIgnoreCase("case3")){
              tvEmailAd.setText("email_address");
          }else if(btnSelected.equalsIgnoreCase("case4")){
              tvEmailAd.setText("email_address");
          }
  
      }   
  
  
  
      send.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              convertEditTextToString();
              Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
              emailIntent.setType("text/plain");
              emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,"email_address");
              emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,subject);
              emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,content);
  
              uris = new ArrayList&lt;Uri&gt;();
  
              for(String file : imgPath) {
                  File fileIn = new File(file);
                  Uri u = Uri.fromFile(fileIn);
                  uris.add(u);
              }
  
              emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
              context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
          }
      });
  
  }
  
      private void convertEditTextToString(){
  
          subject = etSubject.getText().toString();
          content = etContent.getText().toString();
          location= etLocation.getText().toString();
      }       
    }
  </code></pre>
  
  <p>Android manifest :</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;uses-sdk
      android:minSdkVersion="8"
      android:targetSdkVersion="17" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;activity
          android:name="com.example.name.StartScreen"
          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;activity
          android:name="com.example.name.MainActivity"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.example.name.MAINACTIVITY" /&gt;
  
              &lt;category android:name="android.intent.category.DEFAULT" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
       &lt;activity
           android:name="com.example.name.PrevEmail"
           android:label="@string/app_name"&gt;     
       &lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p>And the Logcat :</p>
  
  <pre><code>    12-02 21:44:48.180: W/dalvikvm(29329): threadid=1: thread exiting with uncaught   exception (group=0x40bc4498)
      12-02 21:44:48.180: E/test(29329): Exception
      12-02 21:44:48.200: E/AndroidRuntime(29329): FATAL EXCEPTION: main
      12-02 21:44:48.200: E/AndroidRuntime(29329): java.lang.NullPointerException
      12-02 21:44:48.200: E/AndroidRuntime(29329):    at com.example.name.PrevEmail$1.onClick(PrevEmail.java:100)
      12-02 21:44:48.200: E/AndroidRuntime(29329):    at android.view.View.performClick(View.java:4106)
      12-02 21:44:48.200: E/AndroidRuntime(29329):    at  android.view.View$PerformClick.run(View.java:17150)
      12-02 21:44:48.200: E/AndroidRuntime(29329):    at android.os.Handler.handleCallback(Handler.java:615)
      12-02 21:44:48.200: E/AndroidRuntime(29329):    at android.os.Handler.dispatchMessage(Handler.java:92)
      12-02 21:44:48.200: E/AndroidRuntime(29329):    at android.os.Looper.loop(Looper.java:137)
      12-02 21:44:48.200: E/AndroidRuntime(29329):    at android.app.ActivityThread.main(ActivityThread.java:4792)
      12-02 21:44:48.200: E/AndroidRuntime(29329):    at java.lang.reflect.Method.invokeNative(Native Method)
      12-02 21:44:48.200: E/AndroidRuntime(29329):    at java.lang.reflect.Method.invoke(Method.java:511)
      12-02 21:44:48.200: E/AndroidRuntime(29329):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:808)
      12-02 21:44:48.200: E/AndroidRuntime(29329):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:575)
      12-02 21:44:48.200: E/AndroidRuntime(29329):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>