0

_imagesPathsあるパッケージから別のパッケージに文字列配列を渡そうとしています。

私は次のことを試しました:

//sending the paths of images from `MainActivity` which is in `main.packages`
//assume the array is not null

Intent b = new Intent(MainActivity.this, EditPicturesActivity.class);
b.putExtra("left",LeftImageString);
b.putExtra("right",RightImageString);

パスは、次のようにして別のパッケージで受け取ります。 private String[] _imagesPath; Bundle extras = getIntent().getExtras();
_imagesPath[0] = extras.getString("左"); _imagesPath[1] = extras.getString("右");

次に、パスによって提供された画像を読み込もうとしましたが、というメッセージが表示されNullPointerます_imagesPath is null

編集

_imagesPath の値は、ギャラリーから画像を選択することで割り当てられます: このアクティビティでは

private String[] _imagesPath = null;

case SELECT_PICTURE1:
        if (resultCode == RESULT_OK) {

            Uri selectedImage = data.getData();
            String[] filePathColumn = { MediaStore.Images.Media.DATA };

            Cursor cursor = getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();

            int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            LeftImageString = cursor.getString(columnIndex);

            cursor.close();

            //the toast displays the path and it is not null
            Toast.makeText(
                    getApplicationContext(),
                    "The path of the first image you have selected is:  "
                            + LeftImageString, Toast.LENGTH_SHORT).show();  
            // String leftImagePath contains the path of selected Image


            //intent for "left" is placed here

        }      
        break; 

//similary image is taken for Image 2.
4

3 に答える 3

0

_imagesPaths を直接渡すことができます。

Intent b = new Intent(MainActivity.this, EditPicturesActivity.class);
b.putExtra("paths",_imagesPaths);

そして、次のように反対側でそれを取得できます。

String[] paths = getIntent().getStringArrayExtra("paths");
于 2013-10-13T13:26:13.523 に答える
0

you must initialise _imagesPath before you set values to it:

String _imagesPath[] = new String[2];
Bundle extras = getIntent().getExtras();            
_imagesPath[0] = extras.getString("left");
_imagesPath[1] = extras.getString("right");
于 2013-10-13T13:15:43.940 に答える