1

我正在尝试运行查询以从 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                     
4

1 回答 1

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);

因为你没有任何主机变量

于 2013-01-07T14:56:12.840 回答