【问题标题】:Getting a sqlite exception获取 sqlite 异常
【发布时间】:2020-12-06 06:14:00
【问题描述】:

我是 SQLite 的初学者,在突出显示的行中遇到此异常- 引起:android.database.sqlite.SQLiteException: no such table: VocabDatabase (code 1 SQLITE_ERROR): , while compile: SELECT Word, Meaning FROM VocabDatabase WHERE _id = ?

我的 MainActivity 代码 -

try {
        **strong textCursor cursor = db.query(DatabaseHelper.DB_name, new String[]{"Word", "Meaning"},
                "_id = ?", new String[]{Integer.toString(0)}, null, null, null);**
        if (cursor.moveToFirst()) {
            String word = cursor.getString(0);
            String meaning = cursor.getString(0);
            TextView tv1 = findViewById(R.id.tv1);
            TextView tv2 = findViewById(R.id.tv2);
            tv1.setText(word);
            tv2.setText(meaning);
        }
        cursor.close();
        db.close();

    }catch(SQLException e){
        Toast.makeText(this, "Can't access the database", Toast.LENGTH_SHORT).show();
    }

SQLite 助手 -

 public void onCreate(SQLiteDatabase db)
{   db.execSQL("create table Vocabwords (_id integer primary key autoincrement, Word text, Meaning text)");
insertNewEntry(db, "Diabolic","Evil");
insertNewEntry(db,"Concede","Agree to an argument after declaring it incorrect in past");
} 

【问题讨论】:

  • 但是no such table: VocabDatabase消息中有什么不清楚的地方?

标签: android sqlite android-sqlite


【解决方案1】:

VocabDatabase 是一个database 名称,但在SELECT 子句中,您需要一个table 名字。

可能表名是Vocabwords,请再检查一下。

【讨论】:

    猜你喜欢
    • 2011-07-03
    • 1970-01-01
    • 2010-11-01
    • 2015-10-07
    • 1970-01-01
    • 1970-01-01
    • 2014-03-04
    • 1970-01-01
    • 2013-04-29
    相关资源
    最近更新 更多