我有一個數據庫已經包含一個表「LocalLogin」,並且已經正確設置並且可以在沒有問題的情況下被查詢,正在設置與我的新表「PersonList」一樣。然而,當我嘗試執行上PersonList查詢選擇一些價值觀,我得到的錯誤在數據庫上執行查詢時Android「android.database.sqlite.SQLiteException:沒有這樣的表」錯誤
android.database.sqlite.SQLiteException: no such table: PersonList: , while compiling: SELECT ...
它給我的表從來沒有創建的想法,雖然我的onCreate方法執行創建查詢我的SQLiteOpenHelper類。與LocalLogin具有相同的數據庫名稱可能存在的問題?
下面是相關代碼:
數據庫適配器類
public class GoingOutPersonListDbAdapter {
private static final String DATABASE_NAME = "GoingOutData";
private static final String DATABASE_TABLE_PERSONLIST = "PersonList";
private static final int DATABASE_VERSION = 1;
public static final String PERSONLIST_ID = "PersonList_id";
public static final String PERSONLIST_LOGIN = "Login";
public static final String PERSONLIST_PASSWORD = "Password";
private static final String TAG = "Debugstring";
private PersonListDatabaseHelper mPersonListDbHelper;
private SQLiteDatabase mDb;
private static final String DATABASE_CREATE =
"CREATE Table " + DATABASE_TABLE_PERSONLIST+ " ("
+ PERSONLIST_ID + " integer PRIMARY KEY Autoincrement, "
+ PERSONLIST_LOGIN + " text NOT NULL,"
+ PERSONLIST_PASSWORD + " text NOT NULL);";
private final Context mCtx;
private static class PersonListDatabaseHelper extends SQLiteOpenHelper {
PersonListDatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
Log.d(TAG,DATABASE_CREATE);
db.execSQL(DATABASE_CREATE);
}
}
public GoingOutPersonListDbAdapter(Context ctx) {
this.mCtx = ctx;
}
public GoingOutPersonListDbAdapter open() throws SQLException {
mPersonListDbHelper = new PersonListDatabaseHelper(mCtx);
mDb = mPersonListDbHelper.getWritableDatabase();
return this;
}
public Cursor searchPerson(String searchString) {
return mDb.query(DATABASE_TABLE_PERSONLIST, new String[] {PERSONLIST_ID, PERSONLIST_LOGIN, PERSONLIST_PASSWORD}, searchString, null, null, null, null);
}
}
在我的活動類:
private GoingOutPersonListDbAdapter mPersonListDbHelper;
...
mPersonListDbHelper = new GoingOutPersonListDbAdapter(this);
mPersonListDbHelper.open();
...
//loginEditText is properly set
Cursor personList = mPersonListDbHelper.searchPerson(GoingOutPersonListDbAdapter.PERSONLIST_LOGIN + " = '" + loginEditText + "'");
startManagingCursor(personList);
我添加 「\t \t @Override \t \t公共無效onUpgrade(SQLiteDatabase分貝,INT oldVersion,INT NEWVERSION){ \t \t \t db.execSQL(DATABASE_CREATE); \t \t}」,改變了數據庫的版本爲2,但我仍然有相同的錯誤 – 2012-04-09 20:31:36
工程就像一個魅力,我在兩個數據庫適配器中增加數據庫版本,我顯然不應該這樣做 – 2012-04-09 20:58:30
適合我 – 2012-07-12 10:44:10