0
URLConnection을 만들려고하지만 페이지의 내용을 가져 오지 않습니다.URLConnection이 내 이미지를 반환하지 않습니다.
protected Bitmap doInBackground(String... urls) {
String urlStr = urls[0];
Bitmap img = null;
try {
URL url = new URL(urlStr);
Log.d("URL", url.toString());
urlConnection = (HttpURLConnection) url.openConnection(/*proxy*/);
urlConnection.setDoInput(true);
urlConnection.setConnectTimeout(20 * 1000);
urlConnection.setReadTimeout(20 * 1000);
Log.d("Before If", "Here");
if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
Log.d("After If", "Here");
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
img = BitmapFactory.decodeStream(in);
}
} catch (IOException e) {
e.printStackTrace();
}
urlConnection.disconnect();
return img;
}
Logcat은 "Before If : Here"를 표시하지만 After를 표시하지 않습니다. 왜 틀렸어? 그것은 URL 일 수 있습니까? 나는 tryinf이 URL에 액세스 할 수있어 : http://placehold.it/120x120&text=Child%201 그것은 피카소와 같은 더 나은 이미지 로딩 라이브러리, UIL 등을 사용하여 AsyncTask를
어떻게'urlConnection.getResponseCode()'를 로그에 출력하여 여러분이 겪고있는 문제가 무엇인지 정확히 알아내는 법 –