本文介绍了android.database.sqlite.SQLiteConstraintException:错误code 19:约束failedexception的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个名为表的资源的,但是当我在其中插入值,这将引发异常:
I created a table named resources but when I insert values in it, this exception is thrown:
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)";
下面是我的插入的code:
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");
}
}
谁能告诉我在哪里,可能是问题?
Can anyone tell me where could be the problem?
推荐答案
约束失败通常表明你不喜欢的东西传递空
值到该声明为列不为空
当你创建你的表。
Constraint failed usually indicates that you did something like pass a null
value into a column that you declare as not null
when you create your table.
这篇关于android.database.sqlite.SQLiteConstraintException:错误code 19:约束failedexception的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!