0

グリッド ビューで選択した画像の画像パスを uris に変換して、それらをフォト エディターに渡し、そこから編集できるようにしようとしています。

                    if (cb.isChecked()) {
                    String paths = imagePaths.get(i);
                    Uri uri = Uri.parse(paths);
                    editImagesUri[count] = uri;
                    count++;
                }

これは、NullPointerException を取得しているコードであり、問​​題が何であるかを理解できないようです。

基本的に同じことを行うように if ステートメントの内容を数回変更しましたが、エラーは同じです。

これはパスの値です:

imagePaths = new ArrayList<String>();
    imagePaths = getPathOfAllImages(getActivity());

これは uri の値です:

private static Uri[] editImagesUri;

getPathOfAllImages は、このWebサイトで回答として見つけたメソッドです。そのコードは次のとおりです。

public static ArrayList<String> getPathOfAllImages(Activity activity) {
        ArrayList<String> absolutePathOfImageList = new ArrayList<String>();
        String absolutePathOfImage = null;
        String nameOfFile = null;
        String absolutePathOfFileWithoutFileName = null;
        Uri uri;
        Cursor cursor;
        int column_index;
        int column_displayname;
        int lastIndex;
        int counter = 0;
        // absolutePathOfImages.clear();


            uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;

            String[] projection = { MediaColumns.DATA,
                    MediaColumns.DISPLAY_NAME };

            cursor = activity.managedQuery(uri, projection, null, null, null);
            column_index = cursor.getColumnIndexOrThrow(MediaColumns.DATA);

            column_displayname = cursor
                    .getColumnIndexOrThrow(MediaColumns.DISPLAY_NAME);

            // cursor.moveToFirst();
            while (cursor.moveToNext()) {
                // for(int i=0; i<cursor.getColumnCount();i++){
                // Log.i(TAG,cursor.getColumnName(i)+".....Data Present ...."+cursor.getString(i));
                // }
                // Log.i(TAG,"=====================================");

                absolutePathOfImage = cursor.getString(column_index);
                nameOfFile = cursor.getString(column_displayname);

                lastIndex = absolutePathOfImage.lastIndexOf(nameOfFile);

                lastIndex = lastIndex >= 0 ? lastIndex
                        : nameOfFile.length() - 1;

                absolutePathOfFileWithoutFileName = absolutePathOfImage
                        .substring(0, lastIndex);


                    if (absolutePathOfImage != null) {
                        absolutePathOfImageList.add(absolutePathOfImage);
                    }


            }


        // Log.i(TAG,"........Detected images for Grid....."
        // + absolutePathOfImageList);
        return absolutePathOfImageList;
    }
4

0 に答える 0