gpt4 book ai didi

Android-SQLiteConstraintException 错误代码 19 : constraint failed

转载 作者:行者123 更新时间:2023-12-02 06:39:15 25 4
gpt4 key购买 nike

我知道您对此错误有很多疑问,但我无法理解为什么 Logcat 上的所有字段似乎都已正确填写,但即使如此仍会发生故障。

这是表的创建:

public void onCreate(SQLiteDatabase db) {
String ddl = "CREATE TABLE Politician (id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE , idpolitician INTEGER NOT NULL, name TEXT NOT NULL, picture TEXT , position TEXT NOT NULL, country TEXT NOT NULL, state TEXT NOT NULL, city TEXT NOT NULL);";

db.execSQL(ddl);

}

这是我尝试保存的位置。

public void savePolitician(Politician politician) {

ContentValues values = new ContentValues();
values.put("idpolitician", politician.getId());
values.put("name", politician.getName());
values.put("picture", politician.getPictureFilename());
values.put("position", politician.getPosition());
values.put("country", politician.getCountry());
values.put("state", politician.getState());
values.put("city", politician.getCity());

mDatabase.insert("Politician", null, values);

}

这是 LogCat:

01-08 04:03:31.149  32633-32633/? E/Database﹕ [SQLiteDatabase.java:1428:insert()] Error inserting 

state=SP position=governador picture=example idpolitician=1 city=Sao Paulo country=Brasil name=Alckmin

android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed
at android.database.sqlite.SQLiteStatement.native_execute(Native Method)
at android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:61)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1582)
at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1426)
at com.politify.dao.DbManegament.savePolitician(DbManegament.java:44)

如您所见,所有字段均已填充。任何人都可以帮助并告诉我做错了什么

最佳答案

尝试在创建表脚本中删除AUTOINCRMENT UNIQUE

关于Android-SQLiteConstraintException 错误代码 19 : constraint failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20988409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com