これで作業する方法を手伝ってください。私はログインを行っており、すべてのエラーと可能な例外を認証しています。これは私のコードです `
EditText un, pw;
ImageButton login;
TextView error;
ProgressDialog pd;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
un=(EditText)findViewById(R.id.txtUsername);
pw=(EditText)findViewById(R.id.txtPassword);
login=(ImageButton)findViewById(R.id.btnLogin);
error=(TextView)findViewById(R.id.errTxt);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
new login().execute();
}
});
}
public class login extends AsyncTask{
@Override
protected Object doInBackground(Object... params) {
// TODO Auto-generated method stub
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("username", un.getText().toString()));
postParameters.add(new BasicNameValuePair("password", pw.getText().toString()));
//String valid = "1";
String response = null;
try {
response = CustomHttpClient.executeHttpPost("http://www.cjcld.org/dvts1/mobile/login.php", postParameters);
String res=response.toString();
// res = res.trim();
res= res.replaceAll("\\s+","");
//error.setText(res);
if(Integer.parseInt(res)>0){
postParameters.add(new BasicNameValuePair("id", res));
String result = null;
try
{
result = CustomHttpClient.executeHttpPost("http://www.cjcld.org/dvts1/mobile/status.php", postParameters);
String res2=result.toString();
res2= res2.replaceAll("\\s+","");
if(Integer.parseInt(res2)>0){
Intent myIntent = new Intent(getApplicationContext(), dashboard.class);
Bundle logval = new Bundle();
logval.putString("uid", res);
logval.putString("did", res2);
myIntent.putExtras(logval);
startActivity(myIntent);
}else{
Toast.makeText(getApplicationContext(),"No Delivery", Toast.LENGTH_LONG).show();
}
}
catch(Exception e)
{
Toast.makeText(getApplicationContext(),e.toString(), Toast.LENGTH_LONG).show();
}
}
else
{
Toast.makeText(getApplicationContext(),"Sorry!! Incorrect Username or Password", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(),e.toString(), Toast.LENGTH_LONG).show();
}
return null;
}
}
トーストが実行されると、プログラムが終了し、エラーが表示されます。