gpt4 book ai didi

android - java.lang.RuntimeException : Failure delivering result ResultInfo{who=null, request=1888, result=0, data=null} 到 Activity

转载 作者:IT王子 更新时间:2023-10-28 23:42:54 25 4
gpt4 key购买 nike

我的应用程序允许用户按下一个按钮,它会打开相机,他们可以拍照,它会显示在 ImageView 中。如果用户在相机打开时按下或取消,我会强制关闭 - 将结果 ResultInfo{who=null, request=1888, result=0, data=null} 传递给 Activity 失败......所以我猜结果=0 是我需要插入什么才能使此停止强制关闭的问题?

下面是我的代码。我知道我忘记了一些东西,但就是想不通! (诚​​然,我学习 android 开发大约需要 2 周时间)。感谢您的帮助!

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”,但我不知道该怎么做。

下面是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

最佳答案

添加第一个条件应该可以工作:

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);
}
}
}

关于android - java.lang.RuntimeException : Failure delivering result ResultInfo{who=null, request=1888, result=0, data=null} 到 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8373755/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com