【问题标题】:Android exception: cursor.getString(cursor.…ColumnIndex("bucket_id")) must not be nullAndroid 异常:cursor.getString(cursor....ColumnIndex("bucket_id")) 不能为空
【发布时间】:2020-02-11 13:05:51
【问题描述】:

如何在 Android Q 上方调用 cursor.getString() 获取“bucket_id”和“bucket_display_name”?我可以使用 MediaStore.Images.Media.BUCKET_ID 替换 'bucket_id' 来避免这种崩溃吗?

当然,我知道我可以避免得到下面的字符串,cursor-getstringidx-must-not-be-null 回答了这个问题

if (cursor.getType(idx) == FIELD_TYPE_STRING) {
    result = cursor.getString(idx);
}

【问题讨论】:

    标签: android android-cursor


    【解决方案1】:

    发生的一种情况是,在 Android Q 中,根目录中的任何媒体文件(图像、视频等),文件夹名称将返回为 null(在内部存储的情况下)。在以前的版本中,它作为专辑名称返回为 0。只需检查返回的文件夹名称是否为 null 并分配一些默认专辑名称,我猜你可以避免这种崩溃。

    【讨论】:

      猜你喜欢
      • 2016-02-08
      • 1970-01-01
      • 2021-06-30
      • 2020-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多