Here is the code, when selecting an image the app abruptly crashes :/ Please help, I cant progress further without this error being fixed.
Manifest
<activity
android:launchMode="singleTop"
android:name=".FoundMenu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.guruguru2.lostnfound.FOUNDMENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
ImageView XML
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.71"
android:src="@drawable/abc_list_divider_mtrl_alpha" />
.java file
Button pickImageButton = (Button)findViewById(R.id.pick_image_button);
private static final int PICK_IMAGE = 100;
private ImageView imageView2;
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);
}
}
LogCat
E/AndroidRuntime(1083): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=100, result=-1, data=Intent { dat=content://media/external/images/media/16 }} to activity {com.guruguru2.lostnfound/com.guruguru2.lostnfound.FoundMenu}: java.lang.NullPointerException
The main goal here is to select an image from the gallery, and simply show it. I can post more logcat if needed, there is a lot more, this error seemed the most fatal though.