Created
October 31, 2012 20:26
-
-
Save xraymemory/3989602 to your computer and use it in GitHub Desktop.
Android Apache errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static void fetchImage(ArrayList imgUrls, ArrayList bmpArr) { | |
| for (int i = 0; i < imgUrls.size(); i++) { | |
| String urlstr = (String) imgUrls.get(i); | |
| InputStream is = null; | |
| Bitmap bm = null; | |
| try { | |
| System.out.println("URL: " + urlstr); | |
| HttpGet httpRequest = new HttpGet(urlstr); | |
| System.out.println("Request: " + httpRequest); | |
| HttpClient httpclient = new DefaultHttpClient(); | |
| HttpResponse response = (HttpResponse) httpclient | |
| .execute(httpRequest); | |
| HttpEntity entity = response.getEntity(); | |
| BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity( | |
| entity); | |
| is = bufHttpEntity.getContent(); | |
| bm = BitmapFactory.decodeStream(is); | |
| } catch (MalformedURLException e) { | |
| Log.d("RemoteImageHandler", "fetchImage passed invalid URL: " | |
| + urlstr); | |
| } catch (IOException e) { | |
| Log.d("RemoteImageHandler", "fetchImage IO exception: " + e); | |
| } finally { | |
| if (is != null) | |
| try { | |
| is.close(); | |
| } catch (IOException e) { | |
| } | |
| } | |
| bmpArr.add(bm); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 10-31 16:22:50.102: I/System.out(4843): URL: http://ds_product_photos.s3.amazonaws.com/medium/17401.jpg | |
| 10-31 16:22:50.112: I/System.out(4843): Request: org.apache.http.client.methods.HttpGet@412ee880 | |
| 10-31 16:22:50.112: W/dalvikvm(4843): threadid=12: thread exiting with uncaught exception (group=0x40b05300) | |
| 10-31 16:22:50.122: E/AndroidRuntime(4843): FATAL EXCEPTION: AsyncTask #2 | |
| 10-31 16:22:50.122: E/AndroidRuntime(4843): java.lang.RuntimeException: An error occured while executing doInBackground() | |
| 10-31 16:22:50.122: E/AndroidRuntime(4843): at android.os.AsyncTask$3.done(AsyncTask.java:299) | |
| 10-31 16:22:50.122: E/AndroidRuntime(4843): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273) | |
| 10-31 16:22:50.122: E/AndroidRuntime(4843): at java.util.concurrent.FutureTask.setException(FutureTask.java:124) | |
| 10-31 16:22:50.122: E/AndroidRuntime(4843): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307) | |
| 10-31 16:22:50.122: E/AndroidRuntime(4843): at java.util.concurrent.FutureTask.run(FutureTask.java:137) | |
| 10-31 16:22:50.122: E/AndroidRuntime(4843): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) | |
| 10-31 16:22:50.122: E/AndroidRuntime(4843): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) | |
| 10-31 16:22:50.122: E/AndroidRuntime(4843): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) | |
| 10-31 16:22:50.122: E/AndroidRuntime(4843): at java.lang.Thread.run(Thread.java:856) | |
| 10-31 16:22:50.122: E/AndroidRuntime(4843): Caused by: java.lang.IllegalArgumentException: Host name may not be null | |
| 10-31 16:22:50.122: E/AndroidRuntime(4843): at org.apache.http.HttpHost.<init>(HttpHost.java:83) | |
| 10-31 16:22:50.122: E/AndroidRuntime(4843): at org.apache.http.impl.client.AbstractHttpClient.determineTarget(AbstractHttpClient.java:497) | |
| 10-31 16:22:50.122: E/AndroidRuntime(4843): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) | |
| 10-31 16:22:50.122: E/AndroidRuntime(4843): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) | |
| 10-31 16:22:50.122: E/AndroidRuntime(4843): at dealflux.android.MainActivity.fetchImage(MainActivity.java:437) | |
| 10-31 16:22:50.122: E/AndroidRuntime(4843): at dealflux.android.MainActivity$fetchImageTask.doInBackground(MainActivity.java:465) | |
| 10-31 16:22:50.122: E/AndroidRuntime(4843): at android.os.AsyncTask$2.call(AsyncTask.java:287) | |
| 10-31 16:22:50.122: E/AndroidRuntime(4843): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Turns out the issue is that Apache HTTP on Java cannot process URLs with underscores in the hostname .e.g "http://ds_product_photos.s3.amazonaws.com/medium/17401.jpg"