1

I have following 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!"));

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:

E/AndroidRuntime(373): FATAL EXCEPTION: main
E/AndroidRuntime(373): java.lang.NullPointerException: uriString
E/AndroidRuntime(373): at android.net.Uri$StringUri.<init>(Uri.java:422)
E/AndroidRuntime(373): at android.net.Uri$StringUri.<init>(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)

How can I fix this. And why it worked on my devices but on 2 other it didnt?

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?

L3n95
  • 1,505
  • 3
  • 25
  • 49
  • `StatistikDialog.java:140` What is on line # **140** in StatistikDialog.java file? Apparently it should a part of `onClick` event handler. – PM 77-1 Apr 07 '14 at 17:56
  • I have written in Code where it is. It is: Uri file = Uri.parse(path); – L3n95 Apr 07 '14 at 17:58
  • Have you tried putting `Log.d(path);` before this statement? – PM 77-1 Apr 07 '14 at 18:02
  • Do Android versions differ significantly between "good" and "bad" devices? – PM 77-1 Apr 07 '14 at 18:04
  • No not really. Could the reason be, that the "bad" devices have no external sd-card? – L3n95 Apr 07 '14 at 18:11
  • Cause if I remove the sd-card the error comes on the "good" devices too – L3n95 Apr 07 '14 at 18:22
  • This seems to contain your answer: [Why Images.Media.insertImage return null](http://stackoverflow.com/questions/12230942/why-images-media-insertimage-return-null). – PM 77-1 Apr 07 '14 at 18:33
  • It shows me what the problem is but now how to solve it. You know a solution? – L3n95 Apr 07 '14 at 18:54
  • [Saving Images to Internal memory in Android](http://stackoverflow.com/questions/17674634/saving-images-to-internal-memory-in-android) – PM 77-1 Apr 07 '14 at 20:46
  • If I try this nothing happens. No error but if I try to send it nothing happens or at Facebook it says it could'nt load the image. – L3n95 Apr 08 '14 at 15:02

0 Answers0