Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplaying .jpg in an ImageView from the web
    primarykey
    data
    text
    <p>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 needed it's return value of course).</p> <p>Could use a second pair of eyes if you all could be so helpful :)! This is all within my main Activity's class. image.xml (R.layout.image) is has just an ImageView named "imageView1"</p> <pre><code>public void toastGallery(View v) { setContentView(R.layout.image); String uri = "http://www.prelovac.com/vladimir/wp-content/uploads/2008/03/example.jpg"; try { Context context = v.getContext(); InputStream is = (InputStream) fetch(uri); Drawable d = Drawable.createFromStream(is, "src"); ImageView imgView = new ImageView(context); imgView = (ImageView)findViewById(R.id.imageView1); imgView.setImageDrawable(d); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public Object fetch(String address) throws MalformedURLException,IOException { URL url = new URL(address); Object content = url.getContent(); return content; } </code></pre> <p>Logcat info - I'm guessing this is where the StackTrace outputs - please correct me if not! </p> <pre><code>01-02 11:59:09.248: D/gralloc_goldfish(971): Emulator without GPU emulation detected. 01-02 11:59:10.088: D/AndroidRuntime(971): Shutting down VM 01-02 11:59:10.088: W/dalvikvm(971): threadid=1: thread exiting with uncaught exception (group=0x409c01f8) 01-02 11:59:10.128: E/AndroidRuntime(971): FATAL EXCEPTION: main 01-02 11:59:10.128: E/AndroidRuntime(971): java.lang.IllegalStateException: Could not execute method of the activity 01-02 11:59:10.128: E/AndroidRuntime(971): at android.view.View$1.onClick(View.java:3044) 01-02 11:59:10.128: E/AndroidRuntime(971): at android.view.View.performClick(View.java:3511) 01-02 11:59:10.128: E/AndroidRuntime(971): at android.view.View$PerformClick.run(View.java:14105) 01-02 11:59:10.128: E/AndroidRuntime(971): at android.os.Handler.handleCallback(Handler.java:605) 01-02 11:59:10.128: E/AndroidRuntime(971): at android.os.Handler.dispatchMessage(Handler.java:92) 01-02 11:59:10.128: E/AndroidRuntime(971): at android.os.Looper.loop(Looper.java:137) 01-02 11:59:10.128: E/AndroidRuntime(971): at android.app.ActivityThread.main(ActivityThread.java:4424) 01-02 11:59:10.128: E/AndroidRuntime(971): at java.lang.reflect.Method.invokeNative(Native Method) 01-02 11:59:10.128: E/AndroidRuntime(971): at java.lang.reflect.Method.invoke(Method.java:511) 01-02 11:59:10.128: E/AndroidRuntime(971): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 01-02 11:59:10.128: E/AndroidRuntime(971): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 01-02 11:59:10.128: E/AndroidRuntime(971): at dalvik.system.NativeStart.main(Native Method) 01-02 11:59:10.128: E/AndroidRuntime(971): Caused by: java.lang.reflect.InvocationTargetException 01-02 11:59:10.128: E/AndroidRuntime(971): at java.lang.reflect.Method.invokeNative(Native Method) 01-02 11:59:10.128: E/AndroidRuntime(971): at java.lang.reflect.Method.invoke(Method.java:511) 01-02 11:59:10.128: E/AndroidRuntime(971): at android.view.View$1.onClick(View.java:3039) 01-02 11:59:10.128: E/AndroidRuntime(971): ... 11 more 01-02 11:59:10.128: E/AndroidRuntime(971): Caused by: android.os.NetworkOnMainThreadException 01-02 11:59:10.128: E/AndroidRuntime(971): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099) 01-02 11:59:10.128: E/AndroidRuntime(971): at java.net.InetAddress.lookupHostByName(InetAddress.java:391) 01-02 11:59:10.128: E/AndroidRuntime(971): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242) 01-02 11:59:10.128: E/AndroidRuntime(971): at java.net.InetAddress.getAllByName(InetAddress.java:220) 01-02 11:59:10.128: E/AndroidRuntime(971): at libcore.net.http.HttpConnection.&lt;init&gt;(HttpConnection.java:71) 01-02 11:59:10.128: E/AndroidRuntime(971): at libcore.net.http.HttpConnection.&lt;init&gt;(HttpConnection.java:50) 01-02 11:59:10.128: E/AndroidRuntime(971): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351) 01-02 11:59:10.128: E/AndroidRuntime(971): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86) 01-02 11:59:10.128: E/AndroidRuntime(971): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128) 01-02 11:59:10.128: E/AndroidRuntime(971): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308) 01-02 11:59:10.128: E/AndroidRuntime(971): at libcore.net.http.HttpEngine.connect(HttpEngine.java:303) 01-02 11:59:10.128: E/AndroidRuntime(971): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282) 01-02 11:59:10.128: E/AndroidRuntime(971): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232) 01-02 11:59:10.128: E/AndroidRuntime(971): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80) 01-02 11:59:10.128: E/AndroidRuntime(971): at java.net.URLConnection.getContent(URLConnection.java:194) 01-02 11:59:10.128: E/AndroidRuntime(971): at java.net.URL.getContent(URL.java:447) 01-02 11:59:10.128: E/AndroidRuntime(971): at com.tjbiddle.puppywood.PuppyWood.fetch(PuppyWood.java:58) 01-02 11:59:10.128: E/AndroidRuntime(971): at com.tjbiddle.puppywood.PuppyWood.toastGallery(PuppyWood.java:44) 01-02 11:59:10.128: E/AndroidRuntime(971): ... 14 more </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload