2013-03-13 96 views
0

我有一個示例Android應用程序,我在其中創建了一個數據庫,創建了一個表,然後將數據插入表中。第二天,在打開Eclipse IDE並通過模擬器運行我的應用程序時,應用程序突然關閉,SQLLiteException聲稱No such tableandroid.database.sqlite.SQLiteException:沒有這樣的表存在

我的MainActivity代碼如下:

SQLiteDatabase DB = Context.openOrCreateDatabase(
     "WaterElectricityReadingDataBase.db", 
     MODE_WORLD_READABLE, null); 

final String CREATE_TABLE = "create table if not exists " 
     + TABLE_NAME + "(" + COLUMN_NAME_READING_ID 
     + " integer primary key autoincrement," 
     + COLUMN_NAME_READING_MODE + " text not null," 
     + COLUMN_NAME_PASTDATETIME + " date not null, " 
     + "EndDateTime date not null, " 
     + COLUMN_NAME_READINGVALUE + " integer not null" + ");"; 

DB.execSQL(CREATE_TABLE); 

是表或數據不執着?我錯過了設置中的任何內容嗎?

請糾正我,謝謝。

+3

發佈logcat輸出 – 2013-03-13 04:26:59

+0

請參考這個http://stackoverflow.com/questions/10568861/sqliteexception-no-such-table-exists – Anu 2013-03-13 04:27:15

+0

你可以嘗試在手機上運行? – 2013-03-13 04:27:34

回答

0

更改您的代碼,如:

final String CREATE_TABLE = "create table if not exists " 
      + TABLE_NAME + "(" + COLUMN_NAME_READING_ID 
      + " integer primary key autoincrement," 
      + COLUMN_NAME_READING_MODE + " text not null," 
      + COLUMN_NAME_PASTDATETIME + " date not null, " 
      + "EndDateTime date not null, " 
      + COLUMN_NAME_READINGVALUE + " integer not null);"; 

,並告訴我,工作或沒有?

祝你好運。

相關問題