title: Android - Cant access TextView within a Timer in a Service
body: <p>Im facing the following problem:</p>
  
  <pre><code>public class StatCounterService extends Service {
  
  
    private TimerTask updateTask_ref = new TimerTask() {
  
              //Get the element by Id as common practice in Android
          TextView hungerValue_ref = (TextView)layout.findViewById(R.id.hungerValue);
          @Override
          public void run() {
  
            //Every X Seconds, the Tamagotchi loses Hunger Points
            int hunger = (int) (getHunger()-1);
                    //Updating Model (DataBase)
            updateHunger(hunger);
  
                    //Now I want to update the TextView, but this hungerValue is Null 
            hungerValue_ref.setText(new Long(getHunger()).toString());
          }
        };
  }
  </code></pre>
  
  <p>I think the problem is, Im looking for the ID of the View inside a Service, also inside a nested Class (the timertask). The Service is running, i just get a nullpointer on the "hungerValue". Any Ideas how I could solve this?
  thanks a lot!
  Daniel</p>
  
  <p>EDIT: I now try to update the view in the Timer from the activity, here is the idea:</p>
  
  <pre><code>public class MainWindowActivity extends Activity {
  
  
  Timer timer_ref;
  TextView hungerValue_ref;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
              //Change the View I want to change initally (getting Value from Database)
      updateHungerView();
              //Start Timer
      timer_ref = new Timer("StatCounterTimer");
      timer_ref.schedule(updateTask_ref, 1000L, 10000L);
  
  }
      //The Timer from within I want to change the View every X seconds
  private TimerTask updateTask_ref = new TimerTask() {
      @Override
      public void run() {
                      //Line Throws Exception, see Method below
          updateHungerView();
      }
  };
      /**
       * Important Part
       */
  
      public void updateHungerView() {
      hungerValue_ref = (TextView) findViewById(R.id.hungerValue);
      hungerValue_ref.setText(new Long(getHunger()).toString());
  
  }
  </code></pre>
  
  <p>when I try to change the view from my activity, I get this:</p>
  
  <pre><code>09-30 11:54:48.967: ERROR/AndroidRuntime(30476): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
  </code></pre>