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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:02:29+00:00 2026-06-18T00:02:29+00:00

in my android application i’m using Timer schedule.but getting Timer-0 fatal exception as below.how

  • 0

in my android application i’m using Timer schedule.but getting Timer-0 fatal exception as below.how can i remove it.i have also mentioned code below –

01-28 13:44:41.142: E/AndroidRuntime(1307): FATAL EXCEPTION: Timer-0
01-28 13:44:41.142: E/AndroidRuntime(1307):android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
01-28 13:44:41.142: E/AndroidRuntime(1307):     at android.view.ViewRoot.checkThread(ViewRoot.java:2932)
01-28 13:44:41.142: E/AndroidRuntime(1307):     at android.view.ViewRoot.invalidateChild(ViewRoot.java:642)
01-28 13:44:41.142: E/AndroidRuntime(1307):     at android.view.ViewRoot.invalidateChildInParent(ViewRoot.java:668)
01-28 13:44:41.142: E/AndroidRuntime(1307):     at android.view.ViewGroup.invalidateChild(ViewGroup.java:2511)
01-28 13:44:41.142: E/AndroidRuntime(1307):     at android.view.View.invalidate(View.java:5279)
01-28 13:44:41.142: E/AndroidRuntime(1307):     at android.view.View.setBackgroundDrawable(View.java:7626)
01-28 13:44:41.142: E/AndroidRuntime(1307):     at android.view.View.setBackgroundResource(View.java:7535)
01-28 13:44:41.142: E/AndroidRuntime(1307):     at com.example.iqtest.PlayGame$1.run(PlayGame.java:61)
01-28 13:44:41.142: E/AndroidRuntime(1307):     at java.util.Timer$TimerImpl.run(Timer.java:284)

and code is-

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.next);
    but1=(Button) findViewById(R.id.b1);
    but2=(Button) findViewById(R.id.b2);
    but3=(Button) findViewById(R.id.b3);

    myTimer = new Timer();

    myTimer.schedule(new TimerTask() {      

        @Override
        public void run() {
            Random rand=new Random();
            int num=rand.nextInt(9)+1;

            num = rand.nextInt(buttonIds.length);
            int buttonId = buttonIds[num];
            Button bb=(Button) findViewById(buttonId);

            Drawable a=bb.getBackground();
            if(getResources().getDrawable(R.drawable.happy).equals(a))
             bb.setBackgroundResource(R.drawable.happy);
            else
                bb.setBackgroundResource(R.drawable.whoa);
        }
    },0, 1000);
}
  • 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-18T00:02:31+00:00Added an answer on June 18, 2026 at 12:02 am

    use runOnUiThread for updating UI element from Timertask run Method as :

     myTimer.schedule(new TimerTask() {      
    
     @Override
     public void run() {
      Current_Activity.this.runOnUiThread(new Runnable() {
        public void run() {
            // update UI here
        }
     });
     }
    },0, 1000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a Android application using ListView . ListView have a one file in
My Android application was working in English and I have to provide the users
Our android application is getting fairly big and we would like to use functional
In android application we are using Bluetooth connectivity with some of medical devices. To
I have an Android application that targets API 17 and has a minimum SDK
I have a basic Android Application with 2 Fragments. I am trying to fill
In android application i have a custom listview and sqlite database. I want to
My Android application is expecting and array of usernames from my WCF Service using
in android application I am using the Google API for maps. I got the
In my android application, how can I forward user to android market to install

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.