내 Android 용 앱의 Google Cloud Storage 공개 URL에서 이미지를 다운로드하는 중에 문제가 있습니다. 내 코드는 다른 소스의 이미지에서 완벽하게 작동합니다. Google Cloud Storage의 이미지는 문제없이 웹 브라우저에서 액세스 할 수도 있습니다. 예를 들어,이 이미지를 가지고 :
는 java.lang.IllegalArgumentException가 :Android 용 Google Cloud Storage URL에서 이미지를 다운로드 할 수 없습니다.
public class TestService1 extends IntentService {
public TestService1(){
super("TestService1");
}
@Override
protected void onHandleIntent(Intent intent) {
String urlString="http://tin_images.storage.googleapis.com/1420678062-zmj1qJQe126843HbyJvbUI.jpg";
try {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(urlString);
HttpResponse response = httpclient.execute(httpget);
}
catch(IOException e){
e.printStackTrace();
}
}
}
이 나에게 다음과 같은 오류 메시지가 있습니다 : 여기
http://tin_images.storage.googleapis.com/1420678062-zmj1qJQe126843HbyJvbUI.jpg이 문제를 보여주는 intentservice이다 호스트 이름이 null되지 않을 수
public class TestService2 extends IntentService {
public TestService2() {
super("TestService2");
}
@Override
protected void onHandleIntent(Intent intent) {
String urlString="http://tin_images.storage.googleapis.com/1420678062-zmj1qJQe126843HbyJvbUI.jpg";
try {
URL url = new URL(urlString);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.connect();
}
catch(IOException e){
e.printStackTrace();
}
}
}
:
는 또한 HttpURLConnection의를 사용하여 시도 내가 다른 URL을 사용하는 경우 잘 작동 두 경우 모두
http://tin_images.storage.googleapis.com/1420678062-zmj1qJQe126843HbyJvbUI.jpg
:
(캐치 블록에 걸려있다) 여기에 오류가
java.net.UnknownHostException입니다. 나는 앱의 나머지 부분에서 그 라이브러리를 사용하기 때문에 HttpClient를 선호한다.
이 문제를 해결할 수있는 방법이 있습니까?
가보고 여기 보자 http://stackoverflow.com/questions/15121407/solvedhost-name-may-not-be-null-error -in-android를 사용하고 사용중인 httpclient 버전을 확인하십시오. –
Google Cloud Storage에서 양동이의 이름을 tin_images에서 주석 이미지로 변경했는데 문제가 발생했다는 의미입니다. 고맙습니다! 답변을 추가하면이를 수락합니다. –