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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:17:43+00:00 2026-06-12T16:17:43+00:00

I am trying to get a basic timer to work on Android and I

  • 0

I am trying to get a basic timer to work on Android and I have the following code in the onCreate() method:

    editText = (EditText) findViewById(R.id.edit_message);
    Timer time = new Timer();     

    time.schedule(new TimerTask() {
        public void run() {
            timesince++;
            editText.setText("Timeran:"+timesince);
            Log.d("TIMER", "TimerTask run");
        }}, 0, 1000);

So hopefully it would update the textbox with a increasing value (timesince) -which is declared at top of program, along with editText…

However, (although I get no compile issues) when I run it on the emulator it does not work at all. App says ‘blahblahblah has stopped working…’

Am I doing Timers wrong? What am I missing?

Thanks alot.

(P.S. App works fine if this code is removed so I know there is an issue with this section.)

EDIT: I believe this is my logcat output, sorry for wall of text:

10-11 03:40:49.260: E/AndroidRuntime(561): FATAL EXCEPTION: Timer-0
10-11 03:40:49.260: E/AndroidRuntime(561): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
10-11 03:40:49.260: E/AndroidRuntime(561):  at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:3939)
10-11 03:40:49.260: E/AndroidRuntime(561):  at android.view.ViewRootImpl.invalidateChild(ViewRootImpl.java:714)
10-11 03:40:49.260: E/AndroidRuntime(561):  at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:763)
10-11 03:40:49.260: E/AndroidRuntime(561):  at android.view.ViewGroup.invalidateChild(ViewGroup.java:4012)
10-11 03:40:49.260: E/AndroidRuntime(561):  at android.view.View.invalidate(View.java:8454)
10-11 03:40:49.260: E/AndroidRuntime(561):  at android.widget.TextView.invalidateCursor(TextView.java:4319)
10-11 03:40:49.260: E/AndroidRuntime(561):  at android.widget.TextView.spanChange(TextView.java:7670)
10-11 03:40:49.260: E/AndroidRuntime(561):  at android.widget.TextView$ChangeWatcher.onSpanAdded(TextView.java:8020)
10-11 03:40:49.260: E/AndroidRuntime(561):  at android.text.SpannableStringBuilder.sendSpanAdded(SpannableStringBuilder.java:898)
10-11 03:40:49.260: E/AndroidRuntime(561):  at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:614)
10-11 03:40:49.260: E/AndroidRuntime(561):  at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:520)
10-11 03:40:49.260: E/AndroidRuntime(561):  at android.text.Selection.setSelection(Selection.java:76)
10-11 03:40:49.260: E/AndroidRuntime(561):  at android.text.Selection.setSelection(Selection.java:87)
10-11 03:40:49.260: E/AndroidRuntime(561):  at android.text.method.ArrowKeyMovementMethod.initialize(ArrowKeyMovementMethod.java:302)
10-11 03:40:49.260: E/AndroidRuntime(561):  at android.widget.TextView.setText(TextView.java:3244)
10-11 03:40:49.260: E/AndroidRuntime(561):  at android.widget.TextView.setText(TextView.java:3110)
10-11 03:40:49.260: E/AndroidRuntime(561):  at android.widget.EditText.setText(EditText.java:78)
10-11 03:40:49.260: E/AndroidRuntime(561):  at android.widget.TextView.setText(TextView.java:3085)
10-11 03:40:49.260: E/AndroidRuntime(561):  at com.example.cultivation.MainActivity$1.run(MainActivity.java:54)
10-11 03:40:49.260: E/AndroidRuntime(561):  at java.util.Timer$TimerImpl.run(Timer.java:284)
  • 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-12T16:17:45+00:00Added an answer on June 12, 2026 at 4:17 pm
    android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
    

    This is the problem

    You have to move the portion of the background task that updates the ui onto the main thread or create the mHandler in your UI thread;

    Update:

    Updating the UI from a Timer : http://android-developers.blogspot.com/2007/11/stitch-in-time.html

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

Sidebar

Related Questions

I'm having a doozie of a time trying to get a basic http test
i can get the .htpasswd to work with .htaccess I have the following lines
I'm trying to get some basic ecma scripting to work in an svg document
I'm trying to get a basic flip animation transition working when I push a
I'm trying to get a basic datagrid for simple tabular input. The server will
I'm trying to get a basic sample across domains working, but I just cannot
I am trying to get a basic understanding on how to use fputc in
I've been trying to get a basic OAuth interaction working without success. There are
I'm trying to get started with Three20 and just want to get a basic
I am trying to get my head round some basic erlang functionality and I

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.