我是初学者,我无法找到为什么这不会向我展示图像。
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();
}
}
这是我在logcat中遇到的错误" E / BitmapFactory:无法解码流:java.lang.NullPointerException"