2013-03-17 4 views
2

PHP에서 데이터를 읽고 JSON Object를 사용하여 데이터를 가져 왔습니다. 그리고 데이터베이스에서 얻으려는 데이터 중 하나가 BLOB입니다. 다음 코드를 사용하여 직접 시도했습니다.안드로이드에서 JSON 객체로부터 BLOB 가져 오기

products = new JSONArray(getJSONUrl(url)); 
// looping through product 
for (int i = 0; i < products.length(); i++) { 
    JSONObject jsonObj = products.getJSONObject(i); 
    try { 
     placeName = jsonObj.getString(String.valueOf(TAG_PlaceName)); 
     placeDesc = jsonObj.getString(TAG_PlaceDesc); 
     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(placeName, placeDesc, bmp)); 
    } catch (SQLException e) { 
     e.printStackTrace(); 
    } 
} 
  • RowItem 내가 데이터를 유지하는 클래스입니다.

누구든지 내 코드에서 잘못된 점을 지적 할 수 있습니까? 나는 많은 시간 동안 주변을 둘러 보려고했지만 여전히 해결책을 찾을 수 없다.

그런데 앱을 실행 해 보았을 때 UI에 아무런 문제가없는 것처럼 보입니다. 단지 내가 데이터를 보여주기 위해 사용하는 listview는 아무것도 가지고 있지 않은 것처럼 보인다.

+0

는 던져 예외합니까? –

+0

오류가 전혀 없습니다. – TheTree

답변

0

사용이 코드

 @Override 
     protected Bitmap doInBackground(String... params) { 
      String id = params[0]; 
      String add = "http://user localhost/ImageUpload/getImage.php?id="+id; 
      URL url = null; 
      Bitmap image = null; 
      try { 
       url = new URL(add); 
       image = BitmapFactory.decodeStream(url.openConnection().getInputStream()); 
      } catch (MalformedURLException e) { 
       e.printStackTrace(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
      return image; 
     } 
관련 문제