我有以下代码
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!"));
在我的手机和其他所有设备都很完美,但是2台三星设备却给我一个错误。我这里没有这两个设备,所以我尝试使用模拟器,而LogCat给了我以下错误:
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)
我该如何解决这个问题。为什么它在我的设备上运行,但另外两个它没有?
似乎原因是,如果设备没有外部SD卡,则会出现错误。你知道如何解决这个问题吗?