SQLite - 列未创建

时间:2015-05-12 04:20:52

标签: android sqlite

我已经阅读了之前的帖子,但没有提供可行的解决方案(重启模拟器,逗号,间距调整)。

创建一个简单的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=test@email.com 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 个答案:

答案 0 :(得分:0)

是的,尽管重新启动了模拟器,但似乎我在另一个Android Studio窗口中运行的第二个应用程序,使用相同的数据库名称,每次运行主应用程序时都会启动。

感谢您回答,很抱歉浪费您的时间。