我试图将图像和一些字符串一起输入数据库,但我在put方法上得到以下错误:
The method put(String, String) in the type ContentValues is not applicable for the arguments (String, Byte[])
但是当我在教程中看到它时,它似乎和我做的完全一样。
下面是相关代码:
private static final String DATABASE_CREATE =
"CREATE Table " + DATABASE_TABLE_LIST + " ( "
+ LIST_ID + " integer PRIMARY KEY Autoincrement, "
+ LIST_NAME + " text NOT NULL, "
+ LIST_ADDRESS + " text NOT NULL, "
+ LIST_IMAGE + " BLOB );";
...
public long createItem(String name, String address, Byte[] image) {
ContentValues initialValues = new ContentValues();
initialValues.put(LIST_NAME, name);
initialValues.put(LIST_ADDRESS, address);
initialValues.put(LIST_IMAGE, image);
return mDb.insert(DATABASE_TABLE_LIST, null, initialValues);
}
我猜这可能与字符串和字节数组有关,但我不知道如何解决它,也无法通过Google搜索找到它
2条答案
按热度按时间sg24os4d1#
我觉得很奇怪,你试图插入一个Byte数组。你的图像数据很可能是一个byte数组。由于没有针对Byte对象数组的put方法,而只有针对原始数据类型 byte 的数组,编译器不知道该怎么做。
kognpnkq2#
看这里:
https://web.archive.org/web/20200718180158/http://www.tutorialforandroid.com/2009/10/how-to-insert-image-data-to-sqlite.html