2010-08-10 48 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