我已经在代码中实现了这一点,但它给出了一个无法将 BLOB 转换为 long 的错误。在这里,我有一段已实现的代码,但出现错误:
Cursor cur = myDbHelper.getImages(); //images has been recieved in cursor
ImageAdapter adapter = new ImageAdapter(this, cur);
lst.setAdapter(adapter);
/* ImageAdapter Class*/
public ImageAdapter(Context context, Cursor cursor) {
super(context, cursor);
this.context = context;
this.cursor = cursor;
}
public View newView(Context context, Cursor cursor, ViewGroup arg2) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.residentgallery, null);
ImageView iv = (ImageView) view.findViewById(R.id.iv1);
if(cursor.moveToFirst())
{
do
{
System.out.println("byte array");
byte[] data = cursor.getBlob(cursor.getColumnIndex("images"));
ByteArrayInputStream imageStream = new ByteArrayInputStream(data);
Bitmap theImage = BitmapFactory.decodeStream(imageStream);
iv.setImageBitmap(theImage);
System.out.println("Imageview");
}
while(cursor.moveToNext());
}
return view;
}
运行此代码后,我收到此错误:
android.database.sqlite.SQLiteException: unknown error: Unable to convert BLOB to long
我在 BLOB 数据类型的 sqlite 中保存了图像。伙计们,请帮帮我。