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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:54:59+00:00 2026-06-09T04:54:59+00:00

I have created an application that uses twitter 4j i am trying to run

  • 0

I have created an application that uses twitter 4j i am trying to run on different threads to make it faster but i got that errors

08-03 16:02:02.138: E/AndroidRuntime(439): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
08-03 16:02:02.138: E/AndroidRuntime(439):  at android.view.ViewRoot.checkThread(ViewRoot.java:2802)
08-03 16:02:02.138: E/AndroidRuntime(439):  at android.view.ViewRoot.invalidateChild(ViewRoot.java:607)
08-03 16:02:02.138: E/AndroidRuntime(439):  at android.view.ViewRoot.invalidateChildInParent(ViewRoot.java:633)
08-03 16:02:02.138: E/AndroidRuntime(439):  at android.view.ViewGroup.invalidateChild(ViewGroup.java:2505)
08-03 16:02:02.138: E/AndroidRuntime(439):  at android.view.View.invalidate(View.java:5139)
08-03 16:02:02.138: E/AndroidRuntime(439):  at android.widget.AbsListView.resetList(AbsListView.java:1011)
08-03 16:02:02.138: E/AndroidRuntime(439):  at android.widget.ListView.resetList(ListView.java:493)
08-03 16:02:02.138: E/AndroidRuntime(439):  at android.widget.ListView.setAdapter(ListView.java:422)
08-03 16:02:02.138: E/AndroidRuntime(439):  at android.app.ListActivity.setListAdapter(ListActivity.java:267)
08-03 16:02:02.138: E/AndroidRuntime(439):  at a.a.a.StatusListActivity.loadHomeTimeline(StatusListActivity.java:91)
08-03 16:02:02.138: E/AndroidRuntime(439):  at a.a.a.StatusListActivity.access$0(StatusListActivity.java:84)
08-03 16:02:02.138: E/AndroidRuntime(439):  at a.a.a.StatusListActivity$2.run(StatusListActivity.java:78)

here it’s my code

public class StatusListActivity extends ListActivity{



    private Otweet app;
    private Twitter twitter;
    private OAuthHelper authhelper;
    private LoadMoreListItem headerView;
    private LoadMoreListItem FooterView;
    private StatusListAdapter adapter;
    protected ProgressDialog progressdialog;
    private Handler handler=new Handler();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        app=(Otweet)getApplication();
        twitter=app.gettwitter();
        System.setProperty("twitter4j.http.useSSL","false");
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setContentView(R.layout.main);

    }
    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        if(!app.isAuthorized())
        {
        beginAuthorization();
        }
        else
        {
            if(null==getListAdapter())
            loadHomeTimelineifnotloaded();
        }
    }

    public void beginAuthorization()
    {
        Intent intent=new Intent(StatusListActivity.this,AuthorizationActivity.class);
        startActivity(intent);
    }

    private void loadHomeTimelineifnotloaded() {
        // TODO Auto-generated method stub
    //  progressdialog=ProgressDialog.show(StatusListActivity.this,"Load home timeline","loading");
        Thread LoadHomeTimeline=new Thread(){
            public void run()
            {
            loadHomeTimeline();
            handler.post(FinishedLoadingTasks);
            }
        };
        LoadHomeTimeline.start();
    }
    private void loadHomeTimeline()
    {
    try {


        ArrayList<Status> status=twitter.getHomeTimeline();
        adapter=new StatusListAdapter(this, status);
        setListAdapter(adapter);
        setloadMoreViews();
        setListAdapter(adapter);
        getListView().setSelection(1);


    } catch (TwitterException e) {
        // TODO Auto-genera ted catch block
        e.printStackTrace();
        Toast.makeText(getApplicationContext(), "jj", Toast.LENGTH_SHORT).show();
    }

}

    private Runnable FinishedLoadingTasks=new Runnable() {

        public void run() {
            // TODO Auto-generated method stub
            finishedLoadinglist();
        }


    };

    public void finishedLoadinglist()
    {
        setloadMoreViews();
        setListAdapter(adapter);
        getListView().setSelection(1);
    //  progressdialog.dismiss();

    }
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        // TODO Auto-generated method stub
        if(v.equals(headerView))
        {
            headerView.showProgress();
            try {
                headerView.showProgress();
                loadnewerTweets();
            } catch (TwitterException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        else if

            (v.equals(FooterView))
            {
                FooterView.showProgress();
                try {
                    LoadOlderTweets();
                } catch (TwitterException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }

    private void LoadOlderTweets() throws TwitterException {
        // TODO Auto-generated method stub
    FooterView.hideProgress();
    ArrayList<Status> statii=twitter.getHomeTimeline(new Paging().maxId(adapter.getLastId()));
    adapter.appendOlder(statii);    
    }
    private void loadnewerTweets() throws TwitterException {
        // TODO Auto-generated method stub


        //try {
            headerView.showProgress();
            setProgressBarIndeterminateVisibility(true);
            Thread loadMoreThread=new Thread()
            {
                public void run()
                {
                    try {
                ArrayList<Status> statii = twitter.getHomeTimeline(new Paging().sinceId(adapter.getFirstId()));
                        Runnable finishedLoadingNewerTask=new LoadNewerResults(statii);
                        handler.post(finishedLoadingNewerTask);
                    } catch (TwitterException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }


                }
            };

    //  }
//  catch (TwitterException e) {
            // TODO Auto-generated catch block
    //      throw new RuntimeException("Unable to load home timeline",e);
    //  }



    }

    protected void finishedLoadingNewer(ArrayList<Status> statii)
    {

        adapter.appendNewer(statii);
        headerView.hideProgress();
        setProgressBarIndeterminateVisibility(false);
        getListView().setSelection(1);
    }
    private class LoadNewerResults implements Runnable
    {

        private ArrayList<Status> statii;
        public LoadNewerResults(ArrayList<Status> statii)
        {
            super();
            this.statii=statii;
        }
        public void run() {
            // TODO Auto-generated method stub
            finishedLoadingNewer(statii);
        }

    }
    private void setloadMoreViews() {
        // TODO Auto-generated method stub

        headerView=(LoadMoreListItem)getLayoutInflater().inflate(R.layout.load_more, null);
        headerView.showHeaderText();
        FooterView=(LoadMoreListItem)getLayoutInflater().inflate(R.layout.load_more,null);
        FooterView.showFooterText();
        getListView().addHeaderView(headerView);
        getListView().addFooterView(FooterView);
    }



    }

I have searched for these errors and i found that i have to run something on the main thread.can someone fix it and explain it to me ?Thanks very much

  • 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-09T04:55:00+00:00Added an answer on June 9, 2026 at 4:55 am

    all Ui operations need to be done on UI thread so from other threads you can call runonUithread to update Ui elements from other threads.
    But in your case I think you would be better off using Asynctask and update Ui elements in Onprogressupdate and OnpostExecute.

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

Sidebar

Related Questions

I have an application that uses gwt-dnd to make boxes draggable, but when there
I have created an application that uses settings.settings to store some user specific settings
i have created an mvc3 web application that uses forms based authentication. one part
I have never written any code that uses threads. I have a web application
I have created a java SE application that uses the mysql database using mysql
I have create a application that uses the .Net framework 4. I have created
I'm trying to develop a web application that mainly uses PHP but i'm using
We (the people at my company) have created an application for Tomcat that uses
I have created an application that uses Microsoft.Office.Interop.Excel, in my local and testing environments
I have a web application that uses a parser created with Parse::RecDescent. A parser

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.