0

我正在尝试查询数据库中第二个表的数据。

我能够插入数据库(或被引导相信它是成功的)

我已经更改了版本号,但这似乎仍然有效。

谁能看到我在这里做错了什么?

目前我收到以下错误:

日志猫:

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;

这是我的创建方法:

    @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;   
4

1 回答 1

1

挂断第一个onCreate( db )电话。

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
    db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLEAPP);
    onCreate(db);
}
于 2013-01-20T21:19:01.240 回答