在SQLite中运行随机查询时出错

时间:2013-01-07 14:48:56

标签: java android sqlite runtime

我正在尝试运行查询以从SQLite中的表中选择一个随机单词但是当我尝试运行该应用程序时出现此错误?

随机单词方法

public String randWord() {
    SQLiteDatabase db  = this.getWritableDatabase();
    Cursor cur = db.rawQuery("SELECT * FROM TABLE_WORDS ORDER BY RANDOM() LIMIT 1",
    new String[] { "*" }, null);

        String word = cur.getString(cur.getColumnIndex(KEY_WORD));
        return word;         
}

尝试运行应用时出现此错误消息

01-07 14:46:24.448: E/AndroidRuntime(21664): FATAL EXCEPTION: main
01-07 14:46:24.448: E/AndroidRuntime(21664): java.lang.NoSuchMethodError:
android.database.sqlite.SQLiteDatabase.rawQuery                     

1 个答案:

答案 0 :(得分:3)

尝试替换

Cursor cur = db.rawQuery("SELECT * FROM TABLE_WORDS ORDER BY RANDOM() LIMIT 1",
  new String[] { "*" }, null);

Cursor cur = db.rawQuery("SELECT * FROM TABLE_WORDS ORDER BY RANDOM() LIMIT 1", null);

因为您没有任何主变量