我制作了一个SQLite程序,有两列。它完美运行。在我添加了与上面相同的其他列具有相同的表后,我收到了一个错误。为什么会这样?
堆栈追踪:
03-08 09:16:59.570: ERROR/AndroidRuntime(247): Uncaught handler: thread main exiting due to uncaught exception
03-08 09:16:59.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)
答案 0 :(得分:2)
这令人惊讶地像我刚刚在这里回答的一个问题: SQLite Database (why do this?)
如果在onCreate()方法中向表中添加列,则必须升级数据库版本或删除应用程序的用户数据,以便实际触发onCreate()。否则,您的应用程序运行,看到已经具有该名称的数据库,以及相同的版本(该表只有2列),并跳过onCreate(),因此您的表不会被重新创建,并且您的插入失败。
编辑:另一种可能性是你的“逻辑”错字导致了一个问题。如果表格列名称拼写正确为“经度”,则插入将失败,如上所述。