【发布时间】: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