# Can't call method out of a timer. Why? [closed]

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

My situation: I have four FrameLayouts in LinearLayouts.

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);

bar_eat.setMinimumWidth((int)(((float)screen_part/1000)*eat));
bar_drink.setMinimumWidth((int)(((float)screen_part/1000)*drink));
bar_wash.setMinimumWidth((int)(((float)screen_part/1000)*wash));
bar_care.setMinimumWidth((int)(((float)screen_part/1000)*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();

@Override
public void run() {
update_bars()

}

},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.

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