我在图像表字段中有一张图像,我想在我的应用程序中使用该图像 我的 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 中使用此图像时,我会像这样使用它
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)
如何解决空指针异常......当我收到图像字符串......
最佳答案
您可以使用 Picasso 轻松加载图像。例如:
Picasso.with(getActivity()).load(url).into(imageView);
关于php - 从 mysql-php(android) 中检索图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29302981/