I am a beginner and I am unable to find why this is not showing me the image.
public void openRecent(View view){
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent,"CHOOSE``FILE"),REQUEST_CODE);
}
@Override``
protected void onActivityResult(int requestCode, int resultCode,
``Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try{
if(requestCode==REQUEST_CODE && resultCode == RESULT_OK && data!=null) {
Uri imageUri = data.getData();
String[] filePath = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(imageUri,filePath,null,null,null);
if(cursor!=null){
cursor.moveToFirst();
int colIndex = cursor.getColumnIndex(filePath[0]);
String dString = cursor.getString(colIndex);
cursor.close();
ImageView imageView = (ImageView)findViewById(R.id.imageView);
imageView.setImageBitmap(BitmapFactory.decodeFile(dString));
}
}
}catch (Exception e){
e.printStackTrace();
}
}
This is the error I got in logcat "E/BitmapFactory: Unable to decode stream: java.lang.NullPointerException"