Android で Web サービスを AsyncTask クラスに接続しようとしてCaused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
います。これは私のAsyncTask
クラスです
private class LoginTask extends AsyncTask<Void, Void, Void>{
private String user_email1=user_email.getText().toString();
private String user_password1=user_password.getText().toString();
private String returnedJson;
@Override
protected Void doInBackground(Void... params) {
if(isEmailValid(user_email1)){
String authString=user_email1+"::"+user_password1;
try {
ConnectService con = new ConnectService("http://xx.xx.xx.xx:9000/loginUser",EncryptInfo.encrypt(authString));
returnedJson = con.getCatJsonData();
} catch (Exception e) {
System.out.println("Encryption ERROR : "+e.getMessage());
}
}
else{
showMessageBox("Email", "Email hatalı!",false);
login_task.cancel(true);
}
return null;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
user_email1=user_email.getText().toString();
user_password1=user_password.getText().toString();
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
JSONObject json;
try {
json = new JSONObject(returnedJson);
JSONObject loginJson=json.getJSONObject("myHashMap");
if(loginJson.getString("responsestatus").equals("OK")){
login_editor.putString("useremail", user_email1);
login_editor.putString("userpassword", user_password1);
if(!login_editor.commit()){
showMessageBox("LOGIN HATASI!", "Giriş işlemi gerçekleşirken hata oluştu. Lütfen tekrar deneyin.", true);
}
else{
Toast.makeText(LoginActivity.this, "login başarılı", Toast.LENGTH_SHORT).show();
//ÜRÜN ARAMA ACTİVİTESİNE GEÇ***********
}
}
else{
if(loginJson.getString("errorcode").equals("8")){
showMessageBox("LOGIN HATASI!", "Email ve password alanları boş.", true);
}
else if(loginJson.getString("errorcode").equals("9")){
showMessageBox("LOGIN HATASI!", "Geçersiz Email adresi.", true);
}
else if(loginJson.getString("errorcode").equals("10")){
showMessageBox("LOGIN HATASI!", "Şifre minimum 6 karakter olmalı.", true);
}
else if(loginJson.getString("errorcode").equals("11")){
showMessageBox("LOGIN HATASI!", "Girilen hesap sistemde kayıtlı değil.", true);
}
else if(loginJson.getString("errorcode").equals("12")){
showMessageBox("LOGIN HATASI!", "Şifre hatalı.", true);
}
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
protected boolean isEmailValid(CharSequence email) {
return android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches();
}
}