0
我想查詢我的數據庫中的第二個表的數據。沒有這樣的表問題
我能夠插入到數據庫中(或正在帶領相信它是成功的)
我已經改變了版本號,但是這似乎仍有效果都沒有。
任何人都可以看到我在這裏做錯了嗎?
目前,我發現了以下錯誤:
的logcat:
01-20 20:32:15.076: E/AndroidRuntime(303): FATAL EXCEPTION: main
01-20 20:32:15.076: E/AndroidRuntime(303): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.flybase2/com.example.flybase2.ViewAppointments}: android.database.sqlite.SQLiteException: no such table: appointmentTable: , while compiling: SELECT _id, app_name, app_type, app_time, app_date, app_comments FROM appointmentTable ORDER BY app_name ASC
01-20 20:32:15.076: E/AndroidRuntime(303): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.os.Handler.dispatchMessage(Handler.java:99)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.os.Looper.loop(Looper.java:123)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-20 20:32:15.076: E/AndroidRuntime(303): at java.lang.reflect.Method.invokeNative(Native Method)
01-20 20:32:15.076: E/AndroidRuntime(303): at java.lang.reflect.Method.invoke(Method.java:521)
01-20 20:32:15.076: E/AndroidRuntime(303): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-20 20:32:15.076: E/AndroidRuntime(303): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-20 20:32:15.076: E/AndroidRuntime(303): at dalvik.system.NativeStart.main(Native Method)
01-20 20:32:15.076: E/AndroidRuntime(303): Caused by: android.database.sqlite.SQLiteException: no such table: appointmentTable: , while compiling: SELECT _id, app_name, app_type, app_time, app_date, app_comments FROM appointmentTable ORDER BY app_name ASC
01-20 20:32:15.076: E/AndroidRuntime(303): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:46)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1229)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1184)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1301)
01-20 20:32:15.076: E/AndroidRuntime(303): at com.example.flybase2.DBHandler.getAppointmentsData(DBHandler.java:325)
01-20 20:32:15.076: E/AndroidRuntime(303): at com.example.flybase2.ViewAppointments.onCreate(ViewAppointments.java:34)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
列變量:
public static final String KEY_ROWAPPID = "_appid";
public static final String KEY_NAMEAPP = "app_name";
public static final String KEY_TYPEAPP = "app_type";
public static final String KEY_TIMEAPP = "app_time";
public static final String KEY_DATEAPP = "app_date";
public static final String KEY_COMMENTAPP = "app_comments";
public static final String KEY_ALARM = "app_alarm";
表名稱和版本:
private static String DATABASE_TABLEAPP = "appointmentTable";
private static int DATABASE_VERSIONAPP = 1;
我的繼承人創造我的ThOD:
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
KEY_NAME + " TEXT NOT NULL, " +
KEY_TEL + " TEXT NOT NULL, " +
KEY_EMAIL + " TEXT NOT NULL, " +
KEY_COMMENTS + " TEXT NOT NULL);"
);
db.execSQL("CREATE TABLE " + DATABASE_TABLEAPP + " (" +
KEY_ROWAPPID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
KEY_NAMEAPP + " TEXT NOT NULL, " +
KEY_TYPEAPP + " TEXT NOT NULL, " +
KEY_TIMEAPP + " TEXT NOT NULL, " +
KEY_DATEAPP + " TEXT NOT NULL, " +
KEY_COMMENTAPP + " TEXT NOT NULL, " +
KEY_ALARM + " BOOLEAN NOT NULL);"
);
在升級:
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
onCreate(db);
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLEAPP);
onCreate(db);
}
方法用於查詢表:
public Cursor getAppointmentsData() {
String [] columns = new String[]{KEY_ROWAPPID, KEY_NAMEAPP, KEY_TYPEAPP, KEY_TIMEAPP, KEY_DATEAPP, KEY_COMMENTAPP};
Cursor c = ourDatabase.query(DATABASE_TABLEAPP, columns, null, null, null, null, KEY_NAMEAPP + " ASC", null);
return c;
感謝您的回答。你的意思是完全刪除我的onCreate方法?因爲我確定我不能這樣做,因爲它需要一個onCreate和onUpgrade。 – user1352057
或者你的意思是增加我的版本號來升級?正如我已經嘗試過這一點,它仍然給我同樣的錯誤。 – user1352057
我刪除了第二個onCreate,但不幸的是我的問題仍然存在。任何其他想法?因爲我真的不想有一個單獨的數據庫。 – user1352057