「Successfully Registered!」でコードの最後の部分まで到達した場合を除いて、すべてが機能します。次に、タイトルに記載されているエラーが registerDialog メッセージ部分内に表示されます。
何か間違ったことをしていますか?誰かが私のコードをチェックするのを手伝ってくれますか
どうもありがとうございました。
アプリのメイン ページに戻るだけですが、アプリはクラッシュしませんでした。登録ボタンをもう一度押すと、同じエラーが返されます。
private void setRegister(Button b) { b.setOnClickListener(new View.OnClickListener() {
private AsyncTask<String, Void, String> 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<String, Void, String>() {
ProgressDialog dialog2;
ArrayList<NameValuePair> postParameters2;
String response2 = null;
@Override
protected void onPreExecute() {
postParameters2 = new ArrayList<NameValuePair>();
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!") && !result2.equals("Username have to be at least 5 characters") && !result2.equals("Password have to be at least 8 characters") && !result2.equals("Passwords does not match") && !result2.equals("Email field is empty") && !result2.equals("Email field is not valid") && !result2.equals("Phone number Field is empty") && !result2.equals("Phone number is not numeric") && !result2.equals("Phone number is not 8 digit") && !result2.equals("Birthday Field is empty") && !result2.equals("Birthday is not numeric") && !result2.equals("Birthday is not in DDMMYYYY format") && !result2.equals("Gender Field is empty") && !result2.equals("Gender Field is invalid") && !result2.equals("Gender not in the format M or F") && !result2.equals("Duplicate entry '"+rUsername.getText().toString()+"' for key 'username'") && !result2.equals("Duplicate entry '"+rEmail.getText().toString()+"' for key 'email'") && !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();
}
});
}