[英]Android app crashing in onActivityResult method
My android app is crashing in case 2 and case 3 don't work(don't take picture from camera). 我的Android应用程序在情况2和情况3不起作用(不从相机拍照)时崩溃。 Case 0 and Case 1 works well. 情况0和情况1运作良好。
onClick method: onClick方法:
public void onClick(View v) {
if(position == 0 && menuID == mFrameID1)
{
Intent pickPhoto = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(pickPhoto , 1);//pick photo from gallery
}
else if(position == 1 && menuID == mFrameID1)
{
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePicture, 0);//capture from camera
}
else if(position == 0 && menuID == mFrameID2)
{
Intent pickPhoto = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(pickPhoto , 2);//pick photo from gallery
}
else if(position == 1 && menuID == mFrameID2)
{
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePicture, 3);//capture from camera
}
}
onActivityResult method onActivityResult方法
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case 0:
if(resultCode == RESULT_OK){
Bitmap photo = (Bitmap) imageReturnedIntent.getExtras().get("data");
mPhotoConteiner2.setImageBitmap(photo);
}
break;
case 1:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
mPhotoConteiner2.setImageURI(selectedImage);
}
break;
case 2:
if(resultCode == RESULT_OK){
Bitmap photo = (Bitmap) imageReturnedIntent.getExtras().get("data");
mPhotoConteiner1.setImageBitmap(photo);
}
break;
case 3:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
mPhotoConteiner1.setImageURI(selectedImage);
}
break;
}
}
Its crashing at line 它在行崩溃
Bitmap photo = (Bitmap) imageReturnedIntent.getExtras().get("data");
in case 2 在情况2
Sorry for that kind question, im newbie to android programming. 抱歉,我是android编程的新手。 And thx for help. 并寻求帮助。
Oh, the problem was that when I'm wrote code for case 2 and case 3 in wrong places. 哦,问题是当我在错误的地方为案例2和案例3编写代码时。 I should write case2 code in case3 and case3 in case2. 我应该在case3中编写case2代码,在case2中编写case3。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.