我有一个存储在图像表字段中的图片,我想在我的应用程序中使用这张图片。 我的PHP页面是:
$user = array();
$user["image"] = base64_encode($result["image"]);
// success
$response["success"] = 1;
// user node
$response["image_table"] = array();
array_push($response["image_table"], $user);
当我在我的应用程序中使用这个数组时,我使用以下代码...
if (success == 1)
{
address = json.getJSONArray(TAG_IMAGE_TABLE);
for (int i = 0; i < address.length(); i++) {
JSONObject c = address.getJSONObject(i);
image = c.getString(TAG_IMAGE);
}
它会给我返回结果,例如:
json response: {"success":1,"image_table": [{"image":"iVBORw0KGgoAAA...................."
当我在我的图像视图中使用这个图像时,我会像这样使用它:
ImageView ivProperty = ((ImageView) myContentView.findViewById(R.id.image_property));
byte[] decodedString;
try {
decodedString = Base64.decode(image, Base64.URL_SAFE);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
ivProperty.setImageBitmap(decodedByte);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
但是它给了我空指针异常
我的logcat值为
03-27 10:10:44.355: E/AndroidRuntime(2391): java.lang.NullPointerException: Input string was null.
03-27 10:10:44.355: E/AndroidRuntime(2391): at com.big_property_info.Base64.decode(Base64.java:1242)
03-27 10:10:44.355: E/AndroidRuntime(2391): at com.big_property_info.MainActivityMap$GeocoderTask$2.getInfoContents(MainActivityMap.java:314)
如何解决接收图像字符串时出现的空指针异常...