该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

public String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {

Cursor cursor = null;

final String column = "_data";

final String[] projection = {column};

try {

cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);

if (cursor != null && cursor.moveToFirst()) {

final int column_index = cursor.getColumnIndexOrThrow(column);

return cursor.getString(column_index);

}

} finally {

if (cursor != null)

cursor.close();

}

return null;

}

这段代码报错:int column_index = cursor.getColumnIndexOrThrow(column); column '_data' does not exist

问题描述 :

1.定义两个按钮,“导出”、“导入”;

2.点击导出按钮,将一些数据写入内存文件中(写入成功);

3.点击导入按钮,Intent intent = new Intent(Intent.ACTION_GET_CONTENT);

intent.setType("*/*");//无类型限制

intent.addCategory(Intent.CATEGORY_OPENABLE);调取内存根目录

4.选中之前导出的文件,进行读取文件,app直接崩溃

我发现有这样一种情况,我点击导出按钮写入文件后,手机重启后,点击导入按钮读取文件就会读取成功。

还请大神帮忙解决一下,到底是什么原因导致的。

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐