java.lang.RuntimeException:将结果 ResultInfo{who=null, request=1888, result=0, data=null} 传递给活动失败 [英] java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1888, result=0, data=null} to activity
问题描述
我的应用程序允许用户按下一个按钮,它会打开相机,他们可以拍照并显示在 ImageView
中.如果用户在相机打开时按回或取消,我会强制关闭 - 将结果 ResultInfo{who=null, request=1888, result=0, data=null} 传递到活动失败...所以我在猜测结果=0 问题是我需要插入什么才能使此停止强制关闭?
My app allows the user to press a button, it opens the camera, they can take a photo and it will show up in an ImageView
. If the user presses back or cancel while the camera is open I get this force close - Failure delivering result ResultInfo{who=null, request=1888, result=0, data=null} to activity... so i am guessing the result=0 is the issue what would I need to insert to make this stop force closing?
下面是我的代码.我知道我忘记了一些东西,但就是想不通!(不可否认,我大约 2 周才开始学习 android 开发).感谢您的帮助!
Below is my code. I know I am forgetting something but just cant figure it out! (Admittedly I am about 2 weeks into learning android development). Thanks for any help!
private static final int CAMERA_REQUEST = 1888;
private ImageView imageView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.imageView = (ImageView)this.findViewById(R.id.photostrippic1);
ImageView photoButton = (ImageView) this.findViewById(R.id.photostrippic1);
photoButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
我想我需要一个else"在那里的某个地方,但我不知道该怎么做.
I guess I would need a "else" in there somewhere but I dont exactly know to do that.
下面是logcat
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1888, result=0, data=null} to activity {photo.booth.app/photo.booth.app.PhotoboothActivity}: java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:2934)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:2986)
at android.app.ActivityThread.access$2000(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1068)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4293)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at photo.booth.app.PhotoboothActivity.onActivityResult(PhotoboothActivity.java:76)
at android.app.Activity.dispatchActivityResult(Activity.java:4108)
at android.app.ActivityThread.deliverResults(ActivityThread.java:2930)
... 11 more
推荐答案
添加第一个条件应该可以:
Adding this first conditional should work:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode != RESULT_CANCELED){
if (requestCode == CAMERA_REQUEST) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}
}
这篇关于java.lang.RuntimeException:将结果 ResultInfo{who=null, request=1888, result=0, data=null} 传递给活动失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!