我从互联网上借来的这段代码很好地运行在android 2.3.3 API 10上;但是它给了我4.0 API 14的错误。我不擅长编码我需要精确校正如何工作而不参考其他文档。
@Override
protected String doInBackground(String... args) {
// TODO Auto-generated method stub
// Check for success tag
int success;
String username = user.getText().toString();
String password = pass.getText().toString();
try {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("user_name", username));
params.add(new BasicNameValuePair("password", password));
Log.d("request!", "starting");
// getting product details by making HTTP request
JSONObject json = jsonParser.makeHttpRequest(
LOGIN_URL, "POST", params);
// check your log for json response
Log.d("Login attempt", json.toString());
// json success tag
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
Log.d("Login Successful!", json.toString());
Intent i_login = new Intent(Login.this, Concurency_main.class);
i_login.putExtra ( "TextBox_user", user.getText().toString() );
finish();
startActivity(i_login);
return json.getString(TAG_MESSAGE);
}else{
Log.d("Login Failure. Invalid username/password ", json.getString(TAG_MESSAGE));
return json.getString(TAG_MESSAGE);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}