使用相机拍摄图像时出现此错误:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { act=inline-data (has extras) }} to activity {ir.aflak.niaz/ir.aflak.niaz.NewAdd2}: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' 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 'int android.graphics.Bitmap.getWidth()' on a null object reference
它在pre lolipop android上工作正常。这是我的代码:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
OutputURI = data.getData();
Bitmap thePic = null;
try {
thePic = MediaStore.Images.Media.getBitmap(NewAdd2.this.getContentResolver(), OutputURI);
} catch (Exception e1) {
Log.v("this", e1.getMessage());
}
FileOutputStream out = null;
ByteArrayOutputStream bao = new ByteArrayOutputStream();
double width = 0;
double height = 0;
width = thePic.getWidth();
height = thePic.getHeight();
}
错误在这一行: width = thePic.getWidth();
有什么问题?我该怎么办android 5?
谢谢