私はこのコードを持っていますが、ボタンをクリックするとギャラリーが開き、画像を選択するとギャラリーが再び閉じます。そして何も起こりません。ギャラリーで画像を選択
パブリッククラスMainActivityは間違っている何AppCompatActivity {
private Button loadimagebutton;
private ImageView imageView;
private static int RESULT_LOAD_IMAGE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loadimagebutton = (Button) findViewById(R.id.button);
loadimagebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data){
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
imageView = (ImageView)findViewById(R.id.imageView);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
else{
Toast.makeText(getApplicationContext(), "ERROR", Toast.LENGTH_LONG).show();
}
}
を拡張しますか?
にImageViewのを設定することができますか? ERRORトーストなし?クラッシュはない?さて、 'decodeFile()'は有効なビットマップの代わりに 'null'を返しました。使用前に確認し、報告してください。 – greenapps
Log.dをif文に入れて、ロジックを正しく処理しているかどうかを確認しましたか? – drew