Internet task which modifies the view - CalledFromWrongThreadException
<p>I want to modify the TextViews of a tabbed Activity view using a TimerTask.<br>
Here's the code of the task class:  </p>

<pre><code>    public class QueryServer extends TimerTask {

    public void run(){

        MCQuery mcQuery = new MCQuery(serverAddrress,25565);
        QueryResponse response = mcQuery.basicStat();
        int Onlineplayers = response.getOnlinePlayers();
        int MaxPlayers = response.getMaxPlayers();
        Log.d("MCQuery", "" + Onlineplayers + " OnlinePlayers");

        TextView serverStatus = (TextView) findViewById(R.id.server_status);

        TextView onlinePlayersView = (TextView) findViewById(R.id.online_players);



        serverStatus.setText("Online");

        onlinePlayersView.setText("" + Onlineplayers + "/" + MaxPlayers);
        Log.d("QueryServer", "Querying the server...");

    }
}
</code></pre>

<p>This is the class calling the task:  </p>

<pre><code>    public class FirstTab extends Fragment {

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
            View v = inflater.inflate(R.layout.first_tab, null);



            //check Internet connection
            if (isOnline() == true) {

                Log.d("CheckConnection", "The device is connected to the network");
            } else {
                Log.d("CheckConnection", "The device is NOT connected to the network");
            }

            Timer timer = new Timer();
            TimerTask task = new QueryServer();

            //run the QueryServer task every 3 seconds
            timer.schedule(task, 3000, 3000);


             return v;
    }
}
</code></pre>

<p>This is the error:</p>

<blockquote>
  <p>08-01 20:43:16.759: E/AndroidRuntime(1030): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.</p>
</blockquote>

<p>Thank you.</p>
