0

崩溃在这里......

android.database.sqlite.SQLiteException:靠近“GROUP”:语法错误(Sqlite 代码 1 SQLITE_ERROR):,编译时:SELECT _id,bucket_display_name,bucket_id,_id,来自图像的方向 WHERE((is_pending=0)AND(is_trashed=0 ) AND (volume_name IN ( 'external_primary' ))) AND ((1) GROUP BY 1,(2)) ORDER BY date_modified DESC, (OS error - 2:No such file or directory) at android.database.DatabaseUtils.readExceptionFromParcel (DatabaseUtils.java:184) 在 android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140) 在 android.content.ContentProviderProxy.query(ContentProviderNative.java:423) 在 android.content.ContentResolver.query(ContentResolver.java: 955) 在 android.content.ContentResolver.query(ContentResolver.java:891) 在 android.content.ContentResolver.query(ContentResolver.java:840)

以下是显示所有文件夹或图像相册的方法。

private boolean logGalleryFolders() {
        this.albumList = new ArrayList<>();
        List<Integer> bucketIdList = new ArrayList<>();
        Cursor cur = this.context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[]{"_id", "bucket_display_name", "bucket_id", "_id", "orientation"}, "1) GROUP BY 1,(2", null, "date_modified DESC");

        List<GridViewItem> items;
        int i;
        if (cur == null || !cur.moveToFirst()) {
            items = new ArrayList<>();
            for (i = 0; i < this.albumList.size(); i++) {
                items.add(new GridViewItem(this.activity, this.albumList.get(i).name, BuildConfig.FLAVOR + this.albumList.get(i).imageIdList.size(), true, this.albumList.get(i).imageIdForThumb, this.albumList.get(i).orientationList.get(0).intValue()));
            }
            this.albumList.add(new Album());
            this.albumList.get(this.albumList.size() - 1).gridItems = items;
            for (i = 0; i < this.albumList.size() - 1; i++) {
                this.albumList.get(i).gridItems = createGridItemsOnClick(i);
            }

            if (cur != null) {
                cur.close();
            }
            return true;
        }
        int bucketColumn = cur.getColumnIndex("bucket_display_name");
        int bucketId = cur.getColumnIndex("bucket_id");
        int imageId = cur.getColumnIndex("_id");
        int orientationColumnIndex = cur.getColumnIndex("orientation");
        do {
            Album album = new Album();
            int id = cur.getInt(bucketId);
            album.ID = id;
            if (bucketIdList.contains(id)) {
                Album albumFromList = this.albumList.get(bucketIdList.indexOf(album.ID));
                albumFromList.imageIdList.add(cur.getLong(imageId));
                albumFromList.orientationList.add(cur.getInt(orientationColumnIndex));
            } else {
                String bucket = cur.getString(bucketColumn);
                bucketIdList.add(id);
                album.name = bucket;
                album.imageIdForThumb = cur.getLong(imageId);
                album.imageIdList.add(album.imageIdForThumb);
                this.albumList.add(album);
                album.orientationList.add(cur.getInt(orientationColumnIndex));
            }
        } while (cur.moveToNext());
        items = new ArrayList<>();
        for (i = 0; i < this.albumList.size(); i++) {
            items.add(new GridViewItem(this.activity, this.albumList.get(i).name, BuildConfig.FLAVOR + this.albumList.get(i).imageIdList.size(), true, this.albumList.get(i).imageIdForThumb, this.albumList.get(i).orientationList.get(0).intValue()));
        }
        this.albumList.add(new Album());
        this.albumList.get(this.albumList.size() - 1).gridItems = items;
        for (i = 0; i < this.albumList.size() - 1; i++) {
            this.albumList.get(i).gridItems = createGridItemsOnClick(i);
        }
        cur.close();
        return true;
    }

下面是崩溃线......

Cursor cur = this.context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[]{"_id", "bucket_display_name", "bucket_id", "_id", "orientation"}, "1) GROUP BY 1,(2", null, "date_modified DESC");
4

2 回答 2

1

只需更改如下查询:

 Cursor cur = this.context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[]{"_id", "bucket_display_name", "bucket_id", "_id", "orientation"}, "1) GROUP BY 1,(2", null, "date_modified DESC");

Cursor cur = this.context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[]{"_id", "bucket_display_name", "bucket_id", "_id", "orientation"}, null, null, "date_modified DESC");
于 2021-01-21T09:43:41.787 回答
0

GROUP BY进来And了问题。请更改您query的如下:

SELECT
  _id,
  bucket_display_name,
  bucket_id,
  _id,
  orientation
FROM
  images
WHERE
  (
    (is_pending = 0)
    AND (is_trashed = 0)
    AND (volume_name IN ('external_primary'))
  )
  AND ((1))
GROUP BY
  1,(2)
ORDER BY
  date_modified DESC
于 2020-09-16T04:58:43.757 回答