SQLite 外键 NullPointerException

SQLite foreign key NullPointerException

我正在使用 Android studio,sqlite 数据库 我的代码运行正常,但是当我将 "posid" 列添加到 "contacts" table 时,程序无法运行

logcat 同时插入联系人

………… 谢谢大家可以帮助我

您指的是从未初始化的 EditText 引用。即,et4.

此外,我建议不要让成员变量保留对您的视图的引用,因为这是内存泄漏的常见来源。相反,当您需要对视图的本地引用时,只需调用 findViewById。

您没有初始化 EditText et4,这就是异常的原因,当您更新 table 架构时 "add column(s)" 您应该增加数据库版本,以便 android 可以更新 table

int DATABASE_VERSION = 2; // instead of 1