업데이트 : 코드는 정상입니다. 그것은 단순히 데이터베이스에 대한 잘못된 포인터였습니다.(URL) 문자열을 JSONObject로 변환 할 수 없습니다.
JSON 데이터를 가져 오기 위해 HTTP 요청을하기 위해 JSONParser 메서드를 사용하고 데이터베이스에서 JSONObject를 반환합니다. JSONObject를 가져 오는 데 문제가 없으며 이름과 전자 메일과 같은 String을 표시하지만 이미지의 URL은 검색하지 않습니다. 아무런 오류가 없지만 빈 필드 만 표시 중입니다. 나는이
String imageURL = "http://mywebsite.com/images/photo1.png";
에
String imageURL = directory.getString(TAG_IMG);
에서이 라인을 만들 경우
그러나, 그것은 잘 작동합니다.
//URL to make request
private static final String url_veiw_directory = "http://www.myweb.com/android/include/directory_detail_me.php";
private static final String TAG_SUCCESS = "success";
private static final String TAG_DIRECTORY = "directory";
private static final String TAG_ID = "user_id";
private static final String TAG_IMG = "photo"; // Image URLs stored in the DB
private static final String TAG_NAME = "name";
private static final String TAG_EMAIL = "email";
//Get JSONObject by httpRequest
JSONObject json = jsonParser.makeHttpRequest(url_veiw_directory, "GET", params);
Log.d("my profile", json.toString());
if (success == 1) {
JSONArray directoryObj = json.getJSONArray(TAG_DIRECTORY);
JSONObject directory = directoryObj.getJSONObject(0);
//User Image
int loader = R.drawable.loader;
String imageURL = directory.getString(TAG_IMG);
ImageView imagePhoto = (ImageView) findViewById(R.id.photo);
ImageLoader imgLoader = new ImageLoader(getApplicationContext());
imgLoader.DisplayImage(imageURL, loader, imagePhoto);
//User Name and Email
TextView txtName = (TextView) findViewById(R.id.name);
TextView txtEmail = (TextView) findViewById(R.id.email);
txtName.setText(directory.getString(TAG_NAME));
txtEmail.setText(directory.getString(TAG_EMAIL));
//Image Loader Class
public void DisplayImage(String url, int loader, ImageView imageView)
{
stub_id = loader;
imageViews.put(imageView, url);
Bitmap bitmap=memoryCache.get(url);
if(bitmap!=null)
imageView.setImageBitmap(bitmap);
else
{
queuePhoto(url, imageView);
imageView.setImageResource(loader);
}
}
private void queuePhoto(String url, ImageView imageView)
{
PhotoToLoad p=new PhotoToLoad(url, imageView);
executorService.submit(new PhotosLoader(p));
}
private Bitmap getBitmap(String url)
{
File f=fileCache.getFile(url);
//from SD cache
Bitmap b = decodeFile(f);
if(b!=null)
return b;
//from web
try {
Bitmap bitmap=null;
URL imageUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
conn.setConnectTimeout(30000);
conn.setReadTimeout(30000);
conn.setInstanceFollowRedirects(true);
InputStream is=conn.getInputStream();
OutputStream os = new FileOutputStream(f);
ImageUtils.CopyStream(is, os);
os.close();
bitmap = decodeFile(f);
return bitmap;
} catch (Exception ex){
ex.printStackTrace();
return null;
}
}
같은 생기게 하다? 그것을 기록하고 원하는 문자열과 일치하지 않는 이유를 찾아보십시오. 그런 다음 받아 들일 수있는 방법을 찾으십시오. – TheZ
@TheZ, 미안하지만 나는 일종의 초보자입니다. 세부 사항에 친절하게 조금 설명해 주시겠습니까? – user1781367
서버에서 반환 한 JSON 문자열의 예를 게시 하시겠습니까? – Kyle