當我試圖訪問一個表,我有這個錯誤:02-19 16:46:01.677:E/AndroidRuntime(13159):android.database.sqlite.SQLiteException:沒有這樣的表:備註
02-19 16:46:01.677:E/AndroidRuntime(13159):android.database.sqlite.SQLiteException:no such table:notes:INSERT INTO notes(user,text)VALUES('john','testingvalue')
但我創建了表!我在數據庫中有兩個表('用戶'和'筆記'),我以相同的方式訪問它們,但是當我嘗試在表中註釋時,我有這個錯誤。
這是代碼:
package com.loopr;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
public class SQL extends SQLiteOpenHelper {
String createUserTable = "CREATE TABLE users (name TEXT)";
String createNotesTable = "CREATE TABLE notes (user TEXT, text TEXT)";
public SQL(Context context, String name, CursorFactory factory, int version) {
super(context, name, factory, version);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(createNotesTable);
db.execSQL(createUserTable);
}
@Override
public void onUpgrade(SQLiteDatabase db, int before, int after) {
//Nothing at the moment
}
}
我能做些什麼?謝謝。
您是否先創建'user'表,然後更新代碼以創建'notes'表? – waqaslam 2012-02-19 16:01:49
嘗試添加';'在你的SQL語句之後。 – Prexx 2012-02-19 16:07:06