从sqlite获取长字符串时遇到错误。在sqlite中存储长字符串是否有任何限制。 我面临以下错误
Couldn't read row 0, col 0 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
这是我的创建表查询
private static final String CREATE_TABLE2 = "create table " + SHAREDPREFERANCEVIDEO_TABLE + " ( ID INTEGER PRIMARY KEY AUTOINCREMENT,"+
"storedvalue1 TEXT)";
这里是获取单行的功能,这只是我表中的一行
public String sharedprefindb (int position) {
String value="";
String id =Integer.toString(position);
SQLiteDatabase db =this.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM "+ " sharedpreferancevideo_talbe " + " WHERE ID = ? ", new String[] {id});;
if(cursor.getCount()!=0)
{
if(cursor.moveToFirst()){
do{
value=cursor.getString(cursor.getColumnIndex("storedvalue1"));
}while(cursor.moveToNext());
}
cursor.close();
}
return value;
}
我的这段代码在另一个字符串非常小的项目中工作正常 但在这段代码中,我存储了加密数据,因此其文本非常长。 所以任何想法我在哪里做错了。
答案 0 :(得分:0)
<强>更新强> 通过更改您的功能来尝试此解决方案:
public String sharedprefindb (int position) {
String value="";
String id =String.valueOf(position);
SQLiteDatabase db =this.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM "+ " sharedpreferancevideo_talbe " + " WHERE ID = '"+position+"'", null);;
if(cursor!=null && cursor.getCount() > 0)
{
if(cursor.moveToFirst()){
do{
value=cursor.getString(cursor.getColumnIndex(1));
}while(cursor.moveToNext());
}
}
cursor.close();
return value;
}