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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:20:52+00:00 2026-06-08T16:20:52+00:00

I have a problem I can’t set the text of a button during a

  • 0

I have a problem I can’t set the text of a button during a countdown, this is the code:

begin.setText("Start level 1");
begin.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {

final int delay = 0000; // delay for 5 sec.
final int period = 1000; // repeat every sec.
final Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
    public  void run() {
        begin.setText("" + t);
        t--;
        if(t == 0) {
            timer.cancel()
        }
    }
}, delay, period);

this is the logcat:

android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
07-30 17:27:05.273: E/AndroidRuntime(22543):    at android.view.ViewRoot.checkThread(ViewRoot.java:2802)
07-30 17:27:05.273: E/AndroidRuntime(22543):    at android.view.ViewRoot.requestLayout(ViewRoot.java:594)
07-30 17:27:05.273: E/AndroidRuntime(22543):    at android.view.View.requestLayout(View.java:8128)
07-30 17:27:05.273: E/AndroidRuntime(22543):    at android.view.View.requestLayout(View.java:8128)
07-30 17:27:05.273: E/AndroidRuntime(22543):    at android.view.View.requestLayout(View.java:8128)
07-30 17:27:05.273: E/AndroidRuntime(22543):    at android.widget.RelativeLayout.requestLayout(RelativeLayout.java:254)
07-30 17:27:05.273: E/AndroidRuntime(22543):    at android.view.View.requestLayout(View.java:8128)
07-30 17:27:05.273: E/AndroidRuntime(22543):    at android.view.View.requestLayout(View.java:8128)
07-30 17:27:05.273: E/AndroidRuntime(22543):    at android.widget.TextView.checkForRelayout(TextView.java:5405)
07-30 17:27:05.273: E/AndroidRuntime(22543):    at android.widget.TextView.setText(TextView.java:2712)
07-30 17:27:05.273: E/AndroidRuntime(22543):    at android.widget.TextView.setText(TextView.java:2580)
07-30 17:27:05.273: E/AndroidRuntime(22543):    at android.widget.TextView.setText(TextView.java:2555)
07-30 17:27:05.273: E/AndroidRuntime(22543):    at it.bisemanuDEV.piano.livello1$1$1.run(livello1.java:134)
07-30 17:27:05.273: E/AndroidRuntime(22543):    at java.util.Timer$TimerImpl.run(Timer.java:289)

I hope you can help.
Thanks

  • 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-08T16:20:53+00:00Added an answer on June 8, 2026 at 4:20 pm

    As @Jug6ernaut mentioned, you shouldn’t use a TimerTask.
    Instead, you could try using a Handler. This is how I do things like that in a timer.

    For example, in your timer when you want to call .setText(), do this:

    mHandler.post(new Runnable() {
        @Override
        public void run() {
            begin.setText(gcalendar.get(Calendar.MINUTE)+":"+gcalendar.get(Calendar.SECOND));   
        }
    });
    

    It is initialized simply as Handler mHandler = new Handler().

    Edit: Just noticed this is the same idea as the other SO question links posted in the comments below your answer… well, here it is anyways.

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

Sidebar

Related Questions

I have this problem that I can ref a button for control it. I
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have a problem - i can't compile SqlCipher. I'm using this http://groups.google.com/group/sqlcipher/browse_thread/thread/55c6296b56bf4533/c792bbec6df7d4f4?tvc=2#c792bbec6df7d4f4 instructions
I have a problem that I can't resolve. Let's say I have this map
I have this problem I can't figure out, I query the DB this way:
I have a problem i can't find the wrong in this function it sometimes
hello today i have a problem how can this happen ? everything that is
I have a problem: how can I delete a line from a text file
following up on this question , I now have another problem - how can
i have this problem: user can add an HTML description and it will be

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.