title: Only the original thread that created a view hierarchy can touch its views ERROR
body: <p>Everything works except when it reaches till the last part of the code with "Successfully Registered!" then the error as mentioned in the title appears inside the registerDialog message part.</p>
  
  <p>Anything im doing wrongly? can anyone help me check up my code</p>
  
  <p>Thank you very much.</p>
  
  <p>The app didn't crash though it just exit back to the app main page. and if i press the register button again it will return with the same error.</p>
  
  <blockquote>
    <p>private void setRegister(Button b) {
            b.setOnClickListener(new View.OnClickListener() {</p>
  </blockquote>
  
  <pre><code>        private AsyncTask&lt;String, Void, String&gt; task2;
  
          public void onClick(View v) {
              // TODO Auto-generated method stub
              registerDialog = new AlertDialog.Builder(Login.this).create();
              registerDialog.setTitle("Register Alert!");
              registerDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Back", new DialogInterface.OnClickListener() {
  
                          public void onClick(DialogInterface dialog, int which) {
                              // TODO Auto-generated method stub
                              registerDialog.dismiss();
                          }
                      });
  
              task2 = new AsyncTask&lt;String, Void, String&gt;() {
  
                  ProgressDialog dialog2;
                  ArrayList&lt;NameValuePair&gt; postParameters2;
                  String response2 = null;
  
                      @Override
                      protected void onPreExecute() {
                          postParameters2 = new ArrayList&lt;NameValuePair&gt;();
                          postParameters2.add(new BasicNameValuePair("usernamelog", rUsername.getText().toString()));
                          postParameters2.add(new BasicNameValuePair("passwordlog", rPassword.getText().toString()));
                          postParameters2.add(new BasicNameValuePair("rpasswordlog", rRpassword.getText().toString()));
                          postParameters2.add(new BasicNameValuePair("emaillog", rEmail.getText().toString()));
                          postParameters2.add(new BasicNameValuePair("phonenumlog", rPhoneNum.getText().toString()));
                          postParameters2.add(new BasicNameValuePair("doblog", rBirthday.getText().toString()));
                          postParameters2.add(new BasicNameValuePair("genderlog", rGender.getText().toString().toUpperCase(Locale.ENGLISH)));                 
  
                          dialog2 = new ProgressDialog(Login.this, ProgressDialog.STYLE_SPINNER);
                          dialog2.setMessage("Registering...");       
  
                          dialog2.show();
                      }
  
                      @Override
                      protected String doInBackground(String... params) {
                          try {
                              response2 = CustomHttpClient.executeHttpPost("http://whatstherex.info/checkR.php", postParameters2);
  
                              String res2 = response2.toString();
  
                              res2 = res2.replaceAll("null", "");
  
                              if (res2.equals("1")) {
                                  res2 = "Successfully Registered!";
                                  rAuth.setTextColor(Color.GREEN);
                                  return res2;
                              } else {
                                  res2 = res2.toString();
                                  rAuth.setTextColor(Color.RED);
                                  return res2;
                              }
                          } catch (Exception e) {
                              res2 = e.toString();
                              rAuth.setTextColor(Color.BLACK);
                              return res2;
                          }
                      }
  
                      @Override
                      protected void onPostExecute(String result2) {
                          if(!result2.equals("Successfully Registered!") &amp;&amp; !result2.equals("Username have to be at least 5 characters") &amp;&amp; !result2.equals("Password have to be at least 8 characters") &amp;&amp; !result2.equals("Passwords does not match") &amp;&amp; !result2.equals("Email field is empty") &amp;&amp; !result2.equals("Email field is not valid") &amp;&amp; !result2.equals("Phone number Field is empty") &amp;&amp; !result2.equals("Phone number is not numeric") &amp;&amp; !result2.equals("Phone number is not 8 digit") &amp;&amp; !result2.equals("Birthday Field is empty") &amp;&amp; !result2.equals("Birthday is not numeric") &amp;&amp; !result2.equals("Birthday is not in DDMMYYYY format") &amp;&amp; !result2.equals("Gender Field is empty") &amp;&amp; !result2.equals("Gender Field is invalid") &amp;&amp; !result2.equals("Gender not in the format M or F") &amp;&amp; !result2.equals("Duplicate entry '"+rUsername.getText().toString()+"' for key 'username'") &amp;&amp; !result2.equals("Duplicate entry '"+rEmail.getText().toString()+"' for key 'email'") &amp;&amp; !result2.equals("Duplicate entry '"+rPhoneNum.getText().toString()+"' for key 'phoneNum'")){
                          rAuth.setText("Unknown Error!!!");
                          rAuth.setTextColor(Color.BLUE);
                          registerDialog.setMessage(result2);
                          registerDialog.show();
                          dialog2.dismiss();
                          }else if (result2.equals("Duplicate entry '"+rUsername.getText().toString()+"' for key 'username'")) {
                              rAuth.setText("Username already in used");
                              rAuth.setTextColor(Color.RED);
                              registerDialog.setMessage("Username already in used");
                              registerDialog.show();
                              dialog2.dismiss();
                          }else if (result2.equals("Duplicate entry '"+rEmail.getText().toString()+"' for key 'email'")) {
                              rAuth.setText("Email already in used");
                              rAuth.setTextColor(Color.RED);
                              registerDialog.setMessage("Email already in used");
                              registerDialog.show();
                              dialog2.dismiss();
                          }else if (result2.equals("Duplicate entry '"+rPhoneNum.getText().toString()+"' for key 'phoneNum'")){
                              rAuth.setText("Phone number already in used");
                              rAuth.setTextColor(Color.RED);
                              registerDialog.setMessage("Phone number already in used");
                              registerDialog.show();
                              dialog2.dismiss();
                          }else {
                              rAuth.setText("Successfully Registered!");
                              rAuth.setTextColor(Color.GREEN);
                              registerDialog.setMessage("Successfully Registered!");
                              registerDialog.show();
                              dialog2.dismiss();
                          }
                      }
  
              };
              task2.execute();                                    
          }
      });         
  }
  </code></pre>