title: ASyncTask trouble - An error occured while executing doInBackground
body: <p>I'm having some trouble with an AsyncTask. Im trying to reach a php-file thats supposed to connect and check with a MySQL db if username is correct. </p>
  
  <p>The error I am getting is the following: </p>
  
  <pre><code>12-01 14:51:25.815: W/dalvikvm(3216): threadid=11: thread exiting with uncaught exception (group=0x40a13300)
  12-01 14:51:25.927: E/AndroidRuntime(3216): FATAL EXCEPTION: AsyncTask #1
  12-01 14:51:25.927: E/AndroidRuntime(3216): java.lang.RuntimeException: An error occured while executing doInBackground()
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at java.lang.Thread.run(Thread.java:856)
  12-01 14:51:25.927: E/AndroidRuntime(3216): Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4607)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:835)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at android.view.View.requestLayout(View.java:15129)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at android.view.View.requestLayout(View.java:15129)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at android.view.View.requestLayout(View.java:15129)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at android.view.View.requestLayout(View.java:15129)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at android.widget.RelativeLayout.requestLayout(RelativeLayout.java:292)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at android.view.View.requestLayout(View.java:15129)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at android.view.View.requestLayout(View.java:15129)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at android.widget.TextView.checkForRelayout(TextView.java:6309)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at android.widget.TextView.setText(TextView.java:3547)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at android.widget.TextView.setText(TextView.java:3405)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at android.widget.TextView.setText(TextView.java:3380)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at com.example.obligatorisk.MainActivity$loader.doInBackground(MainActivity.java:101)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at com.example.obligatorisk.MainActivity$loader.doInBackground(MainActivity.java:1)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
  12-01 14:51:25.927: E/AndroidRuntime(3216):     ... 5 more
  </code></pre>
  
  <p>(Sorry for the wall of text, not sure whats nessecary to include)</p>
  
  <p><strong>The code I am working with:</strong></p>
  
  <pre><code>protected class loader extends AsyncTask&lt;String, Void, Void&gt; {
  
  
  
      @Override
      protected Void doInBackground(String... params) {
  
  
  
          try {
  
  
              httpclient = new DefaultHttpClient();
              httppost = new HttpPost("http://myurl.com/phplogin.php");
  
              nameValuePairs = new ArrayList&lt;NameValuePair&gt;(1);
              nameValuePairs.add(new BasicNameValuePair("username_in",username.getText().toString().trim()));
              nameValuePairs.add(new BasicNameValuePair("password_in",password.getText().toString().trim()));
              httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
              httppost.getEntity().consumeContent();
  
              response=httpclient.execute(httppost);
  
              ResponseHandler&lt;String&gt; responseHandler = new BasicResponseHandler();
              String response = httpclient.execute(httppost, responseHandler);
  
              //Toast.makeText(MainActivity.this,response, Toast.LENGTH_LONG).show();
  
  
              if(response.equalsIgnoreCase("User Found"))
              {
  
                  startActivity(new Intent("com.example.obligatorisk.BROWSER"));
  
              }
          }
          catch(IOException e){
              e.printStackTrace();
          }
  
          return null;
      }
  
  
      // TODO Auto-generated method stub
  
  }
  </code></pre>
  
  <p>Could someone help me out here? I've been stuck for days.</p>