Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7021521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:27:41+00:00 2026-05-27T23:27:41+00:00

I’m not sure what I’m doing wrong here – it seems that somethings is

  • 0

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).

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”

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;     
}

Logcat info – I’m guessing this is where the StackTrace outputs – please correct me if not!

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.<init>(HttpConnection.java:71)
01-02 11:59:10.128: E/AndroidRuntime(971):  at libcore.net.http.HttpConnection.<init>(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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:27:42+00:00Added an answer on May 27, 2026 at 11:27 pm

    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-02 11:59:10.128: E/AndroidRuntime(971): Caused by: android.os.NetworkOnMainThreadException
    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)
    

    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. onPreExecuteand onPostExecute run in the UI thread while doInBackgroundruns in its own thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.