开发者

Why am I getting this error when adding columns to my SQLite table?

I have made one program of SQLite having two columns. It runs perfectly. After I added other columns same as above having same table, I got an error. Why did this happen?

Stack trace:

03-08 09:16:59.570: ERROR/AndroidRuntime(247): Uncaught handler: thread main exiting due to uncaught exception
03-08 09:16:5开发者_运维知识库9.621: ERROR/AndroidRuntime(247):     java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mb.demo/com.mb.demo.DemoActivity}: android.database.sqlite.SQLiteException: table table1 has no column named logitude: , while compiling: insert into table1(name,address,logitude,latitude,contact)values(?,?,?,?,?)
03-08 09:16:59.621: ERROR/AndroidRuntime(247): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)


This is surprisingly like a question I just answered here: SQLite Database (why do this?)

If you add a column to a table in the onCreate() method, you'll have to upgrade the database version OR delete the user data for the app in order for the onCreate() to actually fire. Otherwise, your app runs, sees a database with by that name already, and the same version (with the table having only 2 columns), and skips the onCreate(), so your table doesn't get re-created, and your insert fails.

EDIT: another possibility is that your 'logitude' typo has caused an issue. If the table column name is spelled correctly as 'longitude', your insert will fail as noted above.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜