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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:57:31+00:00 2026-06-11T09:57:31+00:00

I am a noob to android trying to learn how to properly implement a

  • 0

I am a noob to android trying to learn how to properly implement a progress dialog. I started with some code that queried and parsed twitter results before populating a listview during OnCreate. this worked perfectly. I wanted to to add a progress bar since it takes a few seconds, but ever since i added the progress bar my code has stopped working. I get nullpointer errors during parsing and my app crashes due to an error saying ” Only the original thread that created a view hierarchy can touch its views. ” Any help to resolve this is greatly appreciated.

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    dialog = new ProgressDialog (MainActivity.this);
    dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    dialog.setMessage("Loading... please wait");
    dialog.setIndeterminate(false);
    dialog.setMax(100);
    dialog.setProgress(0);
    dialog.show();

    Runnable runnable = new Runnable() {
        @Override
        public void run() {

    tweets = new ArrayList<Tweet>();

    try {           
        JSONObject jArray = JSONfunctions.getJSONfromURL("http://search.twitter.com/search.json?q=gold%20silver%20news&rpp=15");
        JSONArray parsedTwitter = jArray.getJSONArray("results");       
        if(parsedTwitter.equals("") ){
            Toast.makeText(MainActivity.this, "No nearby locations", Toast.LENGTH_LONG).show();
        }else{
            for (int i = 0; i < parsedTwitter.length(); i++) {
            JSONObject parsedspecific = parsedTwitter.getJSONObject(i);             
        if (i == 0){                
            String from_user = parsedspecific.getString("from_user");
            String text = parsedspecific.getString("text"); 
            String profile_image_url = parsedspecific.getString("profile_image_url");  
            Tweet tweet0 = new Tweet(from_user, text, profile_image_url );
            tweets.add(tweet0);                 
            }
dialog.setProgress(50);
        if (i == 1){                
            String from_user = parsedspecific.getString("from_user");
            String text = parsedspecific.getString("text"); 
            String profile_image_url = parsedspecific.getString("profile_image_url");  
            Tweet tweet1 = new Tweet(from_user, text, profile_image_url );
            tweets.add(tweet1);                 
            }

      }
            }

    } catch (Exception e) {
        Log.e("log_tag", "Error parsing data "+ e.toString());
    }

    ListView listView = (ListView) findViewById(R.id.ListViewId);      
    listView.setAdapter(new UserItemAdapter(MainActivity.this, R.layout.listitem, tweets));


    dialog.setProgress(100);
    dialog.dismiss();
        }
    };

    new Thread(runnable).start();


}
  • 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-11T09:57:32+00:00Added an answer on June 11, 2026 at 9:57 am

    This means the Dialog is in a different Thread and you need a handler to mess with it, try adding the next line before the OnCreate() method:

    Handler handler;
    

    Then on the OnCreate method, instantiate the handler so it is in the same thread as the dialog

    handler = new Handler();
    

    Last, to update the dialog from a different thread you need to use the handler like this:

    handler.post(new Runnable(){
    public void run(){
    //Do here whatever you want to do to the dialog
    dialog.setProgress("whatever integer");
    }
    });
    

    Hope this helps

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

Sidebar

Related Questions

I'm trying to implement a simple HTTP server in Android that handles POST requests,
I am a complete code noob and I'm trying to implement a HAL (specifically
I'm a noob to android and I'm trying to learn how to parse xml
Hii everybody , I am noob at android and need some help... I am
Sorry I am a noob, I am trying to learn about sqlite databases using
This is an Android noob question. I am trying to start an activity of
i have to show some operations in Android,,, but Im having some noob problem,
Hey all, first post and a noob in Android programming, but willing to learn!
I am a noob to android and I am trying to update a sqlite
I'm a noob to android and im am trying to query a sqlite table.

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.