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

  • Home
  • SEARCH
  • 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 6095221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:47:16+00:00 2026-05-23T12:47:16+00:00

I am using Handler to make the UI responsive when doing search. I used

  • 0

I am using Handler to make the UI responsive when doing search. I used Handler but why it still displays the error “Only the original thread that created a view hierarchy can touch its views”.

@Override
public void onClick(final View view) {
    if (view.getId() == R.id.searchButton) {
        processThread(searchEditText.getText().toString());
    }
}

private void processThread(final String word) {
    progressDialog.show();

    new Thread() {
        @Override
        public void run() {

            // This is a long time method.
            searchWord(word);

            searchHandler.sendEmptyMessage(0);
        };
    }.start();
}

private void searchWord(final String word) {
    final String result = dictionaryClient.lookup(word);
    resultTextView.setText(result);
}

private final Handler searchHandler = new Handler() {
    @Override
    public void handleMessage(final Message msg) {
        super.handleMessage(msg);
        progressDialog.dismiss();
    };
};


07-04 22:04:54.699: ERROR/AndroidRuntime(8815): android.view.ViewRoot$CalledFromWrongThreadException:
Only the original thread that created a view hierarchy can touch its views.
07-04 22:04:54.699: ERROR/AndroidRuntime(8815):     at android.view.ViewRoot.checkThread(ViewRoot.java:2802)
07-04 22:04:54.699: ERROR/AndroidRuntime(8815):     at android.view.ViewRoot.requestLayout(ViewRoot.java:594)
07-04 22:04:54.699: ERROR/AndroidRuntime(8815):     at android.view.View.requestLayout(View.java:8125)
07-04 22:04:54.699: ERROR/AndroidRuntime(8815):     at android.view.View.requestLayout(View.java:8125)
07-04 22:04:54.699: ERROR/AndroidRuntime(8815):     at android.view.View.requestLayout(View.java:8125)
07-04 22:04:54.699: ERROR/AndroidRuntime(8815):     at android.view.View.requestLayout(View.java:8125)
07-04 22:04:54.699: ERROR/AndroidRuntime(8815):     at android.view.View.requestLayout(View.java:8125)
07-04 22:04:54.699: ERROR/AndroidRuntime(8815):     at android.widget.ScrollView.requestLayout(ScrollView.java:1200)
07-04 22:04:54.699: ERROR/AndroidRuntime(8815):     at android.view.View.requestLayout(View.java:8125)
07-04 22:04:54.699: ERROR/AndroidRuntime(8815):     at android.widget.TextView.checkForRelayout(TextView.java:5371)
07-04 22:04:54.699: ERROR/AndroidRuntime(8815):     at android.widget.TextView.setText(TextView.java:2688)
07-04 22:04:54.699: ERROR/AndroidRuntime(8815):     at android.widget.TextView.setText(TextView.java:2556)
07-04 22:04:54.699: ERROR/AndroidRuntime(8815):     at android.widget.TextView.setText(TextView.java:2531)
07-04 22:04:54.699: ERROR/AndroidRuntime(8815):     at com.megadict.activity.DictionaryActivity.searchWord(DictionaryActivity.java:135)
07-04 22:04:54.699: ERROR/AndroidRuntime(8815):     at com.megadict.activity.DictionaryActivity.access$1(DictionaryActivity.java:133)
07-04 22:04:54.699: ERROR/AndroidRuntime(8815):     at com.megadict.activity.DictionaryActivity$2.run(DictionaryActivity.java:146)

Edit: I followed this article .

  • 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-23T12:47:17+00:00Added an answer on May 23, 2026 at 12:47 pm

    The problem is this line in searchWord:

    resultTextView.setText(result);
    

    That needs to be executed on the UI thread but is running in the search thread. Replace it with:

    searchHandler.post(new Runnable() {
        @Override
        public void run() {
            resultTextView.setText(result);
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using an error handler on my main calling procedure and letting the other
What is the event handler in Java (using net beans, Swing) that resembles the
What is the event handler in Java (using net beans) that resembles the From_Load
I have the following handler in my page that works fine in Firefox, but
I am using jQuery to make some ajax calls and wonder how people handle
I am trying to disable log rotation, for file handler using, FileHandler fh =
When manipulating Handler Mappings using the Microsoft.Web.Administration namespace, is there a way to remove
I'm using code in the Application_BeingRequest() handler of my Global.asax to do some very
i am using a class which extends Handler class to update my activity UI.
I was writing a database handler class in PHP using the mysqli class and

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.