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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:49:11+00:00 2026-06-05T23:49:11+00:00

I was trying to do something else but kept on removing code thinking that

  • 0

I was trying to do something else but kept on removing code thinking that simplifying things will help in identifying my mistake. This is what I am left with (after a lot of simplification) and still I am not getting it why it is not doing it is supposed to!

public class MyOwnTimerActivity extends Activity {

    int timeLeft = 5;
    TextView timerTextView;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button timerButton = (Button) findViewById(R.id.button1);
        timerTextView = (TextView) findViewById(R.id.timerText);

        Thread timer = new Thread() {
            public void run() {
                try {
                    sleep(3000);
                } 
                catch (InterruptedException e) {
                    e.printStackTrace();
                }
                finally{
                    timerTextView.setText("something");
                }
            }
        };
        timer.start();
    }
}

Error: The application crashed after 3 seconds i.e. after timer goes off.

  • 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-05T23:49:12+00:00Added an answer on June 5, 2026 at 11:49 pm

    Ah, yes)) This is because you try to modify UI from non UI-thread

    Update:

    There are several ways to modify UI from another thread:

  2. Using Handler class with overriding handleMessage() method
  3. Using Activity class with calling runOnUI() method, passing there Runnable object in which run() method you modify UI
  4. Using View.post() or View.postDelayed() methods
  5. The last variant is the most convenient in your case. Modify your code in such manner:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button timerButton = (Button) findViewById(R.id.button1);
        timerTextView = (TextView) findViewById(R.id.timerText);
        timerTextView.postDelayed(
            new Runnable() {
               @Override
               run() {
                   timerTextView.setText("something");
               }
            }, 3000);
    }
    
  • 0
  • Reply
  • Share
    Share
    • Share on Facebook
    • Share on Twitter
    • Share on LinkedIn
    • Share on WhatsApp
    • Report

Sidebar

Related Questions

I'm trying to do a replace on a string like this: $('#example_id').replace(/abc123/g,'something else') But
I'm trying to use Graphviz dot (but am willing to use something else) to
I am just trying something with somebody else's code. I have two functions: int
Trying to pass something to something else. Says undefined. Not sure how or why.
I am trying to open excel 2003 workbook and save it as something else,
I'm trying to do something like this in C++: if(){ int a; } else
I'm trying something like this, but this example does not work. jsObj = {};
I'm trying something new, I would normally do this in C# or VB. But
I'm trying to make a simple link that will toggle my status attribute in
Not solved but I think the problem is something else and not the css

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.