2015-05-12 71 views
2

我已經閱讀了以前的文章,沒有提供工作解決方案(重新啓動模擬器,逗號,間距調整)。SQLite - Column not creating

創建一個簡單的SQLite數據庫,但每次運行時都會收到相同的錯誤;

05-12 04:06:17.541 2063-2063/com.disclosure_scots.disclosure_scots E/SQLiteLog﹕ (1) table login has no column named tel_no 
05-12 04:06:17.542 2063-2063/com.disclosure_scots.disclosure_scots E/SQLiteDatabase﹕ Error inserting [email protected] name=test name tel_no=1231234123 created_at=2015-05-12 06:06:19 uid=55517c3b97a8b8.60336236 
    android.database.sqlite.SQLiteException: table login has no column named tel_no (code 1): , while compiling: INSERT INTO login(email,name,tel_no,created_at,uid) VALUES (?,?,?,?,?) 
      at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) 
      at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889) 
      at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500) 
      at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) 
      at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58) 
      at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31) 
      at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469) 
      at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1341) 
      at com.disclosure_scots.disclosure_scots.SQLiteHandler.addUser(SQLiteHandler.java:85) 
      at com.disclosure_scots.disclosure_scots.RegisterActivity$2.onResponse(RegisterActivity.java:151) 
      at com.disclosure_scots.disclosure_scots.RegisterActivity$2.onResponse(RegisterActivity.java:128) 
      at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60) 
      at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30) 
      at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99) 
      at android.os.Handler.handleCallback(Handler.java:739) 
      at android.os.Handler.dispatchMessage(Handler.java:95) 
      at android.os.Looper.loop(Looper.java:135) 
      at android.app.ActivityThread.main(ActivityThread.java:5257) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:372) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 

我的代碼,我試過這個以不同的間距無效;

// Login Table Columns names 
    private static final String KEY_ID = "id"; 
    private static final String KEY_NAME = "name"; 
    private static final String KEY_EMAIL = "email"; 
    private static final String KEY_UID = "uid"; 
    private static final String KEY_CREATED_AT = "created_at"; 
    private static final String KEY_TEL_NO = "tel_no"; 

    public SQLiteHandler(Context context) { 
     super(context, DATABASE_NAME, null, DATABASE_VERSION); 
    } 

    // Creating Tables 
    @Override 
    public void onCreate(SQLiteDatabase db) { 
     String CREATE_LOGIN_TABLE = "CREATE TABLE " + TABLE_LOGIN + "(" 
       + KEY_ID + " INTEGER PRIMARY KEY, " 
       + KEY_NAME + " TEXT, " 
       + KEY_EMAIL + " TEXT UNIQUE, " 
       + KEY_UID + " TEXT, " 
       + KEY_CREATED_AT + " TEXT, " 
       + KEY_TEL_NO + " TEXT " + ")"; 
     db.execSQL(CREATE_LOGIN_TABLE); 

     Log.d(TAG, "Database tables created"); 
    } 

    // Upgrading database 
    @Override 
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
     // Drop older table if existed 
     db.execSQL("DROP TABLE IF EXISTS " + TABLE_LOGIN); 

     // Create tables again 
     onCreate(db); 
    } 

我是否缺少明顯的東西?

+1

你有沒有卸載你的應用程序? http://stackoverflow.com/questions/21881992/when-is-sqliteopenhelper-oncreate-onupgrade-run – laalto

+3

嘗試增加數據庫版本? –

+1

看起來你從來沒有跑過你的onCreate/onUpgrade方法 – shinjw

回答

0

對,儘管重新啓動模擬器,它似乎是我在另一個Android Studio窗口中運行的第二個應用程序,使用相同的數據庫名稱,每次運行主應用程序時都會啓動。

非常感謝您的回答,抱歉浪費您的時間。