Displaying .jpg In An Imageview From The Web
I'm not sure what I'm doing wrong here - it seems that somethings is wrong with fetch() as the application didn't force close when I commented that section out (And anything that n
Solution 1:
Honeycomb or later is killing all processes that to network IO in the UI thread. This could explain why you don't see the issue when you don't fetch()
. Gingerbread also has a so called strict mode, which can kill such network IO or at least flag it in the logs.
If this is not the case, then please post the stack trace so we can help further.
Your stacktrace confirms what I guessed:
01-0211:59:10.128: E/AndroidRuntime(971): Caused by: android.os.NetworkOnMainThreadException
01-0211:59:10.128: E/AndroidRuntime(971): at java.net.URL.getContent(URL.java:447)
[...]
01-0211:59:10.128: E/AndroidRuntime(971): at com.tjbiddle.puppywood.PuppyWood.fetch(PuppyWood.java:58)
So basically that means that you need to do Network IO in a background thread. One way to achieve this is to e.g. use an AsyncTask
as e.g. in this example code. onPreExecute
and onPostExecute
run in the UI thread while doInBackground
runs in its own thread.
Post a Comment for "Displaying .jpg In An Imageview From The Web"