Gallery.class を介して Main.class クラスの ImageView を変更する方法はありますか?
私のメインクラスonClickは、Gallery.classのメソッドsetImageを呼び出します
public void setImage(int currentView) {
Log.d("fgdsf","dumaan dito");
this.currentView = currentView;
Intent gallery = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(gallery, RESULT_LOAD_IMAGE);
}
これはonActivityResultです
@Override
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();
LayoutInflater inflater = (LayoutInflater) mActivity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.activity_main, null);
if (currentView == 0) {
ImageView imageView = (ImageView) v
.findViewById(R.id.imageView1);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
if(currentView==1)
{
ImageView imageView = (ImageView) v
.findViewById(R.id.imageView2);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}
}
そして、私はこのエラーが発生します
08-07 08:35:08.208: E/AndroidRuntime(15689): 原因: java.lang.NullPointerException 08-07 08:35:08.208: E/AndroidRuntime(15689): android.app.Activity.startActivityForResult(Activity で.java:3370)