Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 返回错误的原始查询_Android_Sqlite_Fts3 - Fatal编程技术网

Android 返回错误的原始查询

Android 返回错误的原始查询,android,sqlite,fts3,Android,Sqlite,Fts3,这不是很好吗 Cursor cursor = ourDatabase.rawQuery("SELECT * FROM " + DATABASE_TABLE + " WHERE " + KEY_NAME + " = \'chaman\'",, null); 我不知道,但我打电话时出错了 cursor.getString(1); 上面说 CursorIndexOutofBoundsException 我已经使用 db.execSQL("CREATE VIRTUAL TABLE " + D

这不是很好吗

Cursor cursor = ourDatabase.rawQuery("SELECT * FROM " + DATABASE_TABLE + " WHERE " +     KEY_NAME + " = \'chaman\'",, null);
我不知道,但我打电话时出错了

cursor.getString(1);
上面说 CursorIndexOutofBoundsException

我已经使用

db.execSQL("CREATE VIRTUAL TABLE " + DATABASE_TABLE
                + " USING fts3 (" + KEY_ID
                + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME
                + " TEXT NOT NULL, " + KEY_ADDRESS
                + " TEXT NOT NULL, " + KEY_CONTACT + " TEXT NOT     NULL, "
                + KEY_BALANCE + " DOUBLE);");
& 我确信查曼存在于我的表中,因为我可以在数据库中查看它


怎么了?请帮帮我。我被困在这里一个小时了/

CursorIndexOutOfBoundException表示您忘记调用
moveToFirst()
,或者确实调用了
moveToFirst()
,但没有检查其结果(即光标为空).

您需要调用


最好使用
cursor.getCount()
检查光标计数,如果计数>0,则执行
moveToFirst
,然后尝试使用
cursor访问元素。getString(1)

请发布所有LogCat错误。不要使用单引号转义\只需按原样放置即可。好的。我以前认为cursor.moveToFirst只是通过查看第一个元素是否为空来检查cursor=null。但谢谢大家。:)@ShivamMangla:A
光标始终最初位于索引-1处(即,在实际位于索引0处的第一条记录之前)。原因是查询机制不知道您想要哪条记录(第一条、第二条、最后一条等)。始终明确检查光标是否为空,并检查
moveToFirst()
的布尔结果,以确保光标至少有一条记录可访问。好的。非常感谢(斯奎恩)
if(cursor.moveToFirst()) {  // returns false if no results
  // do stuff here
}