Reputation: 6709
Is there anything wrong with this table?
public void onCreate(SQLiteDatabase db) {
String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "("
+ KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_FIRST_NAME + " TEXT,"
+ KEY_LAST_NAME + " TEXT," + KEY_MOB_NO + " TEXT,"
+ KEY_HOME_NO + " TEXT," + KEY_WORK_NO + " TEXT,"
+ KEY_HOME_ADDR + " TEXT," + KEY_EMAIL_ADDR + " TEXT,"
+ KEY_WORK_ADDR + " TEXT," + KEY_NOTES + " TEXT" + ");";
db.execSQL(CREATE_CONTACTS_TABLE);
My logcat is saying there are no columns. Any idea why this could be?
EDIT: logcat
09-28 07:47:48.933: E/SQLiteLog(1908): (1) table contacts has no column named home_address
09-28 07:47:48.953: E/SQLiteDatabase(1908): Error inserting home_address= first_name=543 work_address= mobile_number= work_number= last_name=543 notes= home_number= email_address=
09-28 07:47:48.953: E/SQLiteDatabase(1908): android.database.sqlite.SQLiteException: table contacts has no column named home_address (code 1): , while compiling: INSERT INTO contacts(home_address,first_name,work_address,mobile_number,work_number,last_name,notes,home_number,email_address) VALUES (?,?,?,?,?,?,?,?,?)
09-28 07:47:48.953: E/SQLiteDatabase(1908): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
09-28 07:47:48.953: E/SQLiteDatabase(1908): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
09-28 07:47:48.953: E/SQLiteDatabase(1908): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
09-28 07:47:48.953: E/SQLiteDatabase(1908): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
09-28 07:47:48.953: E/SQLiteDatabase(1908): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
09-28 07:47:48.953: E/SQLiteDatabase(1908): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
09-28 07:47:48.953: E/SQLiteDatabase(1908): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
09-28 07:47:48.953: E/SQLiteDatabase(1908): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
09-28 07:47:48.953: E/SQLiteDatabase(1908): at com.example.contactmanager.DatabaseHandler.addContact(DatabaseHandler.java:80)
09-28 07:47:48.953: E/SQLiteDatabase(1908): at com.example.contactmanager.NewContactActivity$1.onClick(NewContactActivity.java:63)
09-28 07:47:48.953: E/SQLiteDatabase(1908): at android.view.View.performClick(View.java:4240)
09-28 07:47:48.953: E/SQLiteDatabase(1908): at android.view.View$PerformClick.run(View.java:17721)
09-28 07:47:48.953: E/SQLiteDatabase(1908): at android.os.Handler.handleCallback(Handler.java:730)
09-28 07:47:48.953: E/SQLiteDatabase(1908): at android.os.Handler.dispatchMessage(Handler.java:92)
09-28 07:47:48.953: E/SQLiteDatabase(1908): at android.os.Looper.loop(Looper.java:137)
09-28 07:47:48.953: E/SQLiteDatabase(1908): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-28 07:47:48.953: E/SQLiteDatabase(1908): at java.lang.reflect.Method.invokeNative(Native Method)
09-28 07:47:48.953: E/SQLiteDatabase(1908): at java.lang.reflect.Method.invoke(Method.java:525)
09-28 07:47:48.953: E/SQLiteDatabase(1908): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-28 07:47:48.953: E/SQLiteDatabase(1908): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-28 07:47:48.953: E/SQLiteDatabase(1908): at dalvik.system.NativeStart.main(Native Method)
Upvotes: 0
Views: 166
Reputation: 43023
Try uninstalling and running the app again. It may be that you added more columns to the definition and the database was already installed so the new columns were not added. onCreate
method is run only once when the database is initially installed. It is never run again. When you need to upgrade, there's a separate method onUpgrade
- but it should be used when you actually release a new version.
Upvotes: 2