0

I want to get the image file from php. In my case I tried to convert image into BLOB first then cast it back after I get it from JSONObject. It says in Logcat that JSONObject can not be cast to java.sql.Blob.

If there is another way please tell.

Here is my code:

            JSONArray array = new JSONArray(getJSONUrl(url));
            for (int i = 0; i < products.length(); i++) {
                JSONObject jsonObj = products.getJSONObject(i);

                placeName = jsonObj.getString(TAG_PlaceName);
                placeDesc = jsonObj.getString(TAG_PlaceDesc);
                placeID = jsonObj.getString(TAG_PlaceID);
                try {
                    Blob blob = (Blob) jsonObj.get(TAG_placeIcon);
                    byte[] byteBlob = blob.getBytes(0,
                                   (int) blob.length());
                    Bitmap bmp = BitmapFactory.decodeByteArray(byteBlob, 0,
                               byteBlob.length);
                    rowItems.add(new RowItem(placeID,placeName,placeDesc,bmp));
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
TheTree
  • 21
  • 1
  • 4
  • Why go through JSON? How do you send it? What does your JSON look like? – 323go Mar 19 '13 at 18:05
  • @323go Heh heh, I'm just a newbie. So I don't know what to do at first. Now I know that the image can be loaded by using url from the server. I thought that I should keep the image files in the database itself. – TheTree Mar 23 '13 at 15:31

0 Answers0