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 8926527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:59:30+00:00 2026-06-15T07:59:30+00:00

I have an Async running to get data from a page I’ve created. It

  • 0

I have an Async running to get data from a page I’ve created. It get’s the text just fine, but when I try and get the image from the image src via another class the app force closes. Here is the code that it force closes on:

public class FullReportActivity extends NavigationActivity {
    private TextView textView;
    private String url = "http://www.backcountryskiers.com/sac/sac-full.html";
    private ImageView ivDangerRose;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        // tell which region this covers
        getSupportActionBar().setSubtitle("...from Sierra Avalanche Center");
        setContentView(R.layout.activity_fullreport);
        textView = (TextView) findViewById(R.id.todaysReport);
        ivDangerRose = (ImageView) findViewById(R.id.dangerRose);
        fetcher task = new fetcher();
        task.execute();
    }

    // GET THE IMAGE and RETURN IT
    public static Bitmap getBitmapFromURL(String src) {
        try {
            URL url = new URL(src);
            HttpURLConnection connection = (HttpURLConnection) url
                    .openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream input = connection.getInputStream();
            Bitmap myBitmap = BitmapFactory.decodeStream(input);
            return myBitmap;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    class fetcher extends AsyncTask<String, Void, String> {
        private ProgressDialog dialog = new ProgressDialog(
                FullReportActivity.this);
        private Document doc = null;
        private Document parse = null;
        private String results = null;
        private String reportDate = null;
        private Bitmap bimage = null;

        @Override
        protected String doInBackground(String... params) {
            try {
                doc = Jsoup.connect(url).get();
                Log.e("Jsoup", "...is working...");
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Log.e("Exception", e.getMessage());
            }

            parse = Jsoup.parse(doc.html());
            results = doc.select("#fullReport").outerHtml();

            Element dangerRoseImg = doc.getElementById("reportRose")
                    .select("img").first();
            String dangerRoseSrc = dangerRoseImg.absUrl("src");
            Log.i("Report Rose IMG", dangerRoseSrc);
            bimage = getBitmapFromURL(dangerRoseSrc);
            ivDangerRose.setImageBitmap(bimage);

            return results;
        }

        @Override
        protected void onPostExecute(String result) {
            dialog.dismiss();
            // smooth out the long scrolling...
            textView.setMovementMethod(ScrollingMovementMethod.getInstance());
            reportDate = parse.select("#reportDate").outerHtml();
            textView.setText(Html.fromHtml(reportDate + results));
            textView.setPadding(30, 20, 20, 10);
        }

        @Override
        protected void onPreExecute() {
            dialog.setMessage("Loading Full Report from the Sierra Avalanche Center...");
            dialog.show();
        }

    }

}

I have run this Async alone to get the image like so without a force close and I don’t understand what i am doing different besides calling the method:

public class MainActivity extends Activity {
    public String durl = "http://www.sierraavalanchecenter.org/dangerrose.png?a=2955";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);    

        new DownloadImageTask((ImageView) findViewById(R.id.dangerrose))
        .execute(durl);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }



    private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
          ImageView bmImage;

          public DownloadImageTask(ImageView bmImage) {
              this.bmImage = bmImage;
          }

          protected Bitmap doInBackground(String... urls) {
              String urldisplay = urls[0];
              Bitmap drose = null;
              try {
                InputStream in = new java.net.URL(urldisplay).openStream();
                drose = BitmapFactory.decodeStream(in);
              } catch (Exception e) {
                  Log.e("Error", e.getMessage());
                  e.printStackTrace();
              }
              return drose;
          }

          protected void onPostExecute(Bitmap result) {
              bmImage.setImageBitmap(result);
          }
        }
}

This class gets the image src and creates a bitmap and puts it into an ImageView, what is different here than on my first class???

Frustrated.

  • 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-06-15T07:59:31+00:00Added an answer on June 15, 2026 at 7:59 am

    You can not modify UI from background thread.

    move ivDangerRose.setImageBitmap(bimage); in onPostExecute

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

Sidebar

Related Questions

I just cannot seem to get the tree grid up and running. I have
I have some async method public static Task<JObject> GetUser(NameValueCollection parameters) { return CallMethodApi(users.get, parameters,
I have the following code: $.ajax({ async: false, url: 'chart_data.php', data: {'option':'high', 'id':id}, dataType:
I have this sample code for async operations (copied from the interwebs) public class
I have a progessbar in an activity but the Async is in an external
Basically, I have one div(divNew) which is being populated with content from another page(thread.php)
I load XML from aspx page by MSXML2.DOMDOCUMENT.3.0 ActiveXObject. var xmlDoc = null; try
I have a particularly long running method that I need to execute from my
I have a long running SQL query inside a page that I've sped up
i have already posted a similar question here, but failed to get a response

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.