Friend's, I have a problem in fetching image from database,when i store the image url in database has Blob data type in sqlite, where the code for inserting is
DefaultHttpClient mHttpClient = new DefaultHttpClient();
HttpGet mHttpGet = new HttpGet("http://www.dashfire.com/jackrobie/media/catalog/product/cache/1/image/97x144/9df78eab33525d08d6e5fb8d27136e95/a/l/alexander_1_1_1.jpg");
HttpResponse mHttpResponse = mHttpClient.execute(mHttpGet);
if (mHttpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity entity = mHttpResponse.getEntity();
if ( entity != null) {
// insert to database
ContentValues values = new ContentValues();
values.put(JR_Constants.NAME, name1);
values.put(JR_Constants.PRICE, price);
values.put(JR_Constants.IMAGE_97, EntityUtils.toByteArray(entity));
the values being seemed in the table has after the above, _id | name | image_97 | price 1 mss & - (its like an alpha symbol) $115.00 2 sss & - " $120.00
the code for table creation here...
public void onCreate(SQLiteDatabase db) { try{ db.execSQL("CREATE TABLE "+TABLE_NAME+" (" +_ID+" INTEGER PRIMARY KEY AUTOINCREMENT," + NAME+" TEXT," + IMAGE_97+" BLOB," + PRICE+" TEXT);"); Log.v("JR_Data","table created"); }catch(Exception e){ Log.v("JR_Data","exception in table created");}
i need to know the format of byte array in table is it simply looks like alpha symbol or some thing else,....from my table.
below the code i fetch the image from db has follows
ImageView myImage = (ImageView) findViewById(R.id.jr_lb_list_icon);
line 1. byte[] bb = c.getBlob(c.getColumnIndex(JR_Constants.IMAGE_97)); try { myImage.setImageBitmap(BitmapFactory.decodeByteArray(bb, 0, bb.length)); }catch(Exception e) { Log.v(TAG, "Error1 " +e); }
From above line 1. mentioned where it contains JR_Constants.IMAGE_97 its string constant.
when fetc开发者_高级运维h and set the image from table it throws an nullpointer exception..what is actually wrong with it,and help me to get image by using above code....
and i'm doing above process when the device is in offline
Thanks in advance.
you mentioned
"ImageView myImage = (ImageView) findViewById(R.id.jr_lb_list_icon);"
this code...please check the ID "jr_lb_list_icon" is imageview or otherthings... i think this id is not for image view...
精彩评论