java - Attempt to get length of null array - retrieve bitmap image from sqlite DB -
i trying retrieve image sqlite database. image stored blob , trying retrieve using array. i'm not sure why doing this. permissions set correctly.
package com.example.joao_.quizathonegroupteamproject.activity; import android.content.context; import android.graphics.bitmap; import android.graphics.bitmapfactory; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.baseadapter; import android.widget.imageview; import android.widget.textview; import com.example.joao_.quizathonegroupteamproject.databaseclasses.user; import com.example.joao_.quizathonegroupteamproject.r; import java.util.arraylist; /** * created quoc nguyen on 13-dec-16. */ public class userlistadapter extends baseadapter { private context context; private int layout; private arraylist<user> foodslist; public userlistadapter(context context, int layout, arraylist<user> foodslist) { this.context = context; this.layout = layout; this.foodslist = foodslist; } @override public int getcount() { return foodslist.size(); } @override public object getitem(int position) { return foodslist.get(position); } @override public long getitemid(int position) { return position; } private class viewholder{ imageview imageview; } @override public view getview(int position, view view, viewgroup viewgroup) { view row = view; viewholder holder = new viewholder(); if(row == null){ layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service); row = inflater.inflate(layout, null); holder.imageview = (imageview) row.findviewbyid(r.id.imgfood); row.settag(holder); } else { holder = (viewholder) row.gettag(); } user food = foodslist.get(position); byte[] tblusersimage = food.getimage(); bitmap bitmap = bitmapfactory.decodebytearray(tblusersimage, 0, tblusersimage.length); holder.imageview.setimagebitmap(bitmap); return row; } }
you can retrieve blob image , stored in byte array this:
byte[] array = cursor.getblob(columnindex); bitmap bitmap = bitmapfactory.decodebytearray(array, 0 ,array.length);
and set image view
holder.imageview.setimagebitmap(bitmap);
Comments
Post a Comment