gpt4 book ai didi

android.database.sqlite.SQLiteConstraintException : error code 19: constraint failedexception

转载 作者:可可西里 更新时间:2023-11-01 18:53:34 26 4
gpt4 key购买 nike

我创建了一个名为resources 的表,但是当我在其中插入值时,抛出了这个异常:

android.database.sqlite.SQLiteConstraintException:
error code 19: constraint failedexception

这是我的创建表语句:

public static final String DATABASE_CREATE = 
"CREATE TABLE " + table_resources + "(ID INTEGER PRIMARY KEY,
KEY_TYPE text, KEY_ENCODING text, KEY_WIDTH text, KEY_HEIGHT text,
KEY_DATA text, KeyIId text)";

以下是我的插入代码:

JSONObject show = data.getJSONObject(i);
if (show.get("type").equals("resource_updates")) {
JSONArray resources = show.getJSONArray("resources");
try {
System.out.println("length of resources is is " + resources.length());
for (int resourceIndex = 0; resourceIndex < resources.length(); resourceIndex++) {
type = resources.getJSONObject(resourceIndex).getString("type").toString();
encoding = resources.getJSONObject(resourceIndex).getString("encoding").toString();
data1 = resources.getJSONObject(resourceIndex).getString("data").toString();
id = resources.getJSONObject(resourceIndex).getString("id").toString();
try {
width = resources.getJSONObject(resourceIndex).getString("width").toString();
} catch (Exception e) {
System.out.println(e);
width = "null";
}
try {
height = resources.getJSONObject(resourceIndex).getString("height").toString();
} catch (Exception e) {
e.printStackTrace();
height = "null";
}
db.insert(type,encoding,width,height, data1,iid);
}
} catch (Exception e) {
e.printStackTrace();
System.out.println(e + "exception");
System.out.println("exception in the resources");
}
}

谁能告诉我问题出在哪里?

最佳答案

约束失败通常表示您做了一些事情,例如将 null 值传递到您在创建表时声明为 not null 的列。

关于android.database.sqlite.SQLiteConstraintException : error code 19: constraint failedexception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8117685/

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