2010-08-10 46 views
0

朋友的, 我存儲的圖像url有一個字節數組在數據庫中有blob類型和在獲取此圖像時我得到nullpointer exception.how我可以解決這個問題,這裏的代碼從數據庫獲取數據... String bb = c.getString(c.getColumnIndex(JR_Constants.IMAGE_97)); Log.v(TAG,bb); 位圖theImage = BitmapFactory.decodeByteArray(bb,0,bb.length); myImage.setImageBitmap(theImage); 我在這裏犯了什麼錯誤。從數據庫中獲取圖像的問題

回答

0

您需要將字符串轉換爲ByteArray。基本上只是做bb.getBytes()強似bb

 
String bb = c.getString(c.getColumnIndex(JR_Constants.IMAGE_97)); 
Log.v(TAG,bb); 
Bitmap theImage = BitmapFactory.decodeByteArray(bb.getBytes(), 0, bb.length()); 
myImage.setImageBitmap(theImage); 

我只是想指出,bb.length應該bb.length()

+0

其實你錯長度。 bb.length是正確的拼寫。 – Sephy 2010-08-10 09:50:45

+0

bb的類型不是數組,因此它是length()方法。 – NebulaFox 2010-08-10 10:23:38