以下是我的源代码:
public void Login() {
SharedPreferences sharedPreferences = getSharedPreferences("Sessions", Context.MODE_PRIVATE) ;
SharedPreferences.Editor editor = sharedPreferences.edit();
EditText EmailAddress = (EditText)findViewById(R.id.Email);
EditText txtPassword = (EditText)findViewById(R.id.Password);
final String Email = EmailAddress.getText().toString().trim();
final String Password = txtPassword.getText().toString().trim();
Globals globals = new Globals();
final ProgressDialog ringProgressDialog = ProgressDialog.show(Login.this, "Please wait ...", "Validating User", true);
ringProgressDialog.setCancelable(true);
RequestQueue queue;
StringRequest stringRequest = new StringRequest(Request.Method.POST, "http://www.jobspot.co.ke/Employee/LoginFuncx",
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
ringProgressDialog.dismiss();
if(Html.fromHtml(response).toString().trim().equals("True"))
{
SharedPreferences sharedpreferences = getSharedPreferences("MySessions", Context.MODE_PRIVATE);
Intent myIntent = new Intent(Login.this, MainActivity.class);
try {
String myJsonResponce = GlobalRecordCheck("wgm_employeeinfo",Email,"EmailAddress");
JSONObject jsonObject = new JSONObject(myJsonResponce);
JSONArray result = jsonObject.getJSONArray("result");
JSONObject object = result.getJSONObject(result.length()-1);
String EmployeeNo = object.getString("EmployeeNo");
String EmployeeName = object.getString("FirstName")+" "+object.getString("OtherNames");
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString("jobSpotEmployeeNo", EmployeeNo);
editor.putString("jobSpotEmployer", EmployeeName);
editor.commit();
Login.this.startActivity(myIntent);
}catch (JSONException e){
Toast.makeText(getApplicationContext(),e.toString() , Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}else {
Toast.makeText(getApplicationContext(), Html.fromHtml(response), Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
ringProgressDialog.dismiss();
Toast.makeText(getApplicationContext(), "An Error xxOccurred " + error.toString(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("Password", Password);
params.put("Email", Email);
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
// do not add anything here
return headers;
}
@Override
public String getBodyContentType() {
return "application/json";
}
};
queue = Volley.newRequestQueue(Login.this);
queue.add(stringRequest);
}
答案 0 :(得分:1)
问题在于我的设备。网络模式设置为仅限GSM。我将它改为GSM / WCDMA auto并且运行正常。使用Retrofit Http库也会出现同样的问题。 Retrofit返回 Retrofit.Retrofit error 。希望这有助于某人