[英]App Crashing After Selecting Picture From Gallery
So whenever I select a picture from the gallery in my app, it crashes. 因此,每当我从应用程序的图库中选择一张图片时,它就会崩溃。 Here is the code for the button to the gallery and selected picture to the imageview.
这是图库按钮和imageview所选图片的代码。
pickImageButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
openGallery();
}
});
}
private void openGallery() { //opens the gallery
Intent gallery =
new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(gallery, PICK_IMAGE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == PICK_IMAGE) {
Uri imageUri = data.getData();
imageView2.setImageURI(imageUri);
}
}
Please comment if you need more information, I desperately need help, as this is a very major roadblock for me. 如果您需要更多信息,请发表评论,我非常需要帮助,因为这对我来说是一个非常主要的障碍。
Without the Logs, I can recommend on the following: 如果没有日志,我可以推荐以下内容:
Make sure that pickImageButton isn't null. 确保pickImageButton不为null。
Make sure that imageView2 isn't null. 确保imageView2不为null。
Make sure that in manifest your Activity is in: 确保清单中的活动位于:
android:launchMode="singleTop"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.