I have another problem i can't solve by myselve.

My situation: I have four FrameLayouts in LinearLayouts.

enter image description here

I color them, set Layout hight and width at wrap content and just change the minwidth to use them as a status or progress bar.

To adjust the bars i have a method:

public void update_bars(){

    FrameLayout bar_eat = (FrameLayout)findViewById(R.id.bar_eat);
    FrameLayout bar_drink = (FrameLayout)findViewById(R.id.bar_drink);
    FrameLayout bar_wash = (FrameLayout)findViewById(R.id.bar_wash);
    FrameLayout bar_care = (FrameLayout)findViewById(R.id.bar_care);


This method works fine from everywhere in my activity. But i also want to call this update_bars() method every second so i made a timer for it.

private void update(){

    Timer timer = new Timer();
    timer.schedule(new TimerTask(){

        public void run() {


    },0,(1000* getResources().getInteger(R.integer.remove_speed_inSecond)));

But at this point it crashes....

The debugger says this:

Thread [<12> Timer-0] (ViewRootImpl$CalledFromWrongThreadException)
Timer$TimerImpl.run() Zeile: 290

So where it the problem? And what can i do? I woud be very happy if someone have an idear because i'm going crazy^^


closed as too localized by Maximus Minimus, Maik Semder, bummzack, Sean Middleditch, MichaelHouse Apr 4 '13 at 22:22

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ Voting to close as "too localized"; this is a "please debug my code for me" question. \$\endgroup\$ – Maximus Minimus Mar 30 '13 at 23:18
  • \$\begingroup\$ Right, it was an question linke this. But what shoud i do else if i can't figurout the problem? \$\endgroup\$ – besnep Mar 31 '13 at 11:21

Timer creates new thread. You can't update UI from non UI thread. Use Handler, AsyncTask or runOnUiThread method.

  • \$\begingroup\$ Thank you sooooo much :) runOnUiThread worked for me. Quit simple^^ :) \$\endgroup\$ – besnep Mar 31 '13 at 0:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.