title: Uri.parse: NullPointerException (Android, Java)
body: <p>I have following Code</p>
  
  <pre><code>        Bitmap cs = null;
          v1.setDrawingCacheEnabled(true);
          v1.buildDrawingCache(true);
          cs = Bitmap.createBitmap(v1.getDrawingCache(true));
          Canvas canvas = new Canvas(cs);
          v1.draw(canvas);
          canvas.save();
          v1.setDrawingCacheEnabled(false);
  
          String path = Images.Media.insertImage(getContext().getContentResolver(), cs, "MyImage", null);
          Uri file = Uri.parse(path);//This is line 140
  
          OutputStream outStream = null;
          try {
              outStream = getContext().getContentResolver().openOutputStream(file);
          } catch (FileNotFoundException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          cs = Bitmap.createScaledBitmap(cs, cs.getWidth()*2, cs.getHeight()*2, true);
          cs.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
  
          //file senden
          Intent sharingIntent = new Intent(Intent.ACTION_SEND);
          sharingIntent.putExtra(Intent.EXTRA_STREAM, file);
          sharingIntent.setType("image/jpeg");
          getContext().startActivity(Intent.createChooser(sharingIntent,"Erfolg teilen!"));
  </code></pre>
  
  <p>On my phone and another all works perfect, but 2 Samsung devices it gives me an error. I don't have any of these 2 devices here, so I tried it with an Emulator and than the LogCat gave me following errors:</p>
  
  <pre><code>E/AndroidRuntime(373): FATAL EXCEPTION: main
  E/AndroidRuntime(373): java.lang.NullPointerException: uriString
  E/AndroidRuntime(373): at android.net.Uri$StringUri.&lt;init&gt;(Uri.java:422)
  E/AndroidRuntime(373): at android.net.Uri$StringUri.&lt;init&gt;(Uri.java:412)
  E/AndroidRuntime(373): at android.net.Uri.parse(Uri.java:384)
  E/AndroidRuntime(373): at com.kila.StatistikDialog.onClick(StatistikDialog.java:140)
  E/AndroidRuntime(373): at android.view.View.performClick(View.java:3100)
  E/AndroidRuntime(373): at android.view.View$PerformClick.run(View.java:11644)
  E/AndroidRuntime(373): at android.os.Handler.handleCallback(Handler.java:587)
  E/AndroidRuntime(373): at android.os.Handler.dispatchMessage(Handler.java:92)
  E/AndroidRuntime(373): at android.os.Looper.loop(Looper.java:126)
  E/AndroidRuntime(373): at android.app.ActivityThread.main(ActivityThread.java:3997)
  E/AndroidRuntime(373): at java.lang.reflect.Method.invokeNative(Native Method)
  E/AndroidRuntime(373): at java.lang.reflect.Method.invoke(Method.java:491)
  E/AndroidRuntime(373): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
  E/AndroidRuntime(373): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
  E/AndroidRuntime(373): at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>How can I fix this. And why it worked on my devices but on 2 other it didnt?</p>
  
  <p><strong>It seems like the reason is, that the error comes, if the device has no external sd-card. Do you know how to fix that?</strong></p>