title: create file of image, android
body: <p>I want to upload an image to my amazon s3 server.
  To do that I need to make a file of the image I want to send but somehow it doesn't work:</p>
  
  <p>Button to select the image:</p>
  
  <pre><code>//When clicked on addimage
          addImage.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  // To open up a gallery browser
                  Intent intent = new Intent();
                  intent.setType("image/*");
                  intent.setAction(Intent.ACTION_GET_CONTENT);
                  startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);
              }
  </code></pre>
  
  <p>When clicked on an image in gallery:</p>
  
  <pre><code>@Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      if (requestCode == PICK_IMAGE &amp;&amp; resultCode == Activity.RESULT_OK &amp;&amp; null != data) {
          urimg = data.getData();
  
           String path = getPath(urimg);
          //create file of image to upload
           images3 = new File(path);
      }
  }
          });
  </code></pre>
  
  <p>The getPath method:</p>
  
  <pre><code>public String getPath(Uri uri) {
          if( uri == null ) {
              return null;
          }
          String[] projection = { MediaStore.Images.Media.DATA };
          Cursor cursor = getActivity().getContentResolver().query(uri, projection, null, null, null);
          if( cursor != null ){
              int column_index = cursor
                      .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
              cursor.moveToFirst();
              return cursor.getString(column_index);
          }
          return uri.getPath();
      }
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>12-05 01:37:13.857  30611-30611/com.laurenswuyts.witpa E/AndroidRuntime﹕ FATAL EXCEPTION: main
      Process: com.laurenswuyts.witpa, PID: 30611
      java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=65537, result=-1, data=Intent { dat=content://com.android.providers.media.documents/document/image:3000 flg=0x1 }} to activity {com.laurenswuyts.witpa/com.laurenswuyts.witpa.Activities.Events.AddEventActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'char[] java.lang.String.toCharArray()' on a null object reference
              at android.app.ActivityThread.deliverResults(ActivityThread.java:3539)
              at android.app.ActivityThread.handleSendResult(ActivityThread.java:3582)
              at android.app.ActivityThread.access$1300(ActivityThread.java:144)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1327)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:135)
              at android.app.ActivityThread.main(ActivityThread.java:5221)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
       Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'char[] java.lang.String.toCharArray()' on a null object reference
              at java.io.File.fixSlashes(File.java:185)
              at java.io.File.&lt;init&gt;(File.java:134)
  </code></pre>