【发布时间】:2015-11-06 13:03:57
【问题描述】:
嘿,伙计们,我在一个应用程序中工作,当我发送 OTP 以验证有错误时,我正在通过 OTP 验证我的手机号码,移动是验证但 catch 块给出错误,Activity 不是转到下一个 Acivity 而不是日志显示
private void verifyOtp(final String otp){
final StringRequest strReq = new StringRequest(Request.Method.POST,
config.Config.URL_VERIFY_OTP, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, response.toString());
try {
JSONObject responseObj = new JSONObject(response);
// Parsing json object response
// response will be a json object
boolean status =responseObj.getBoolean("status");
if (status==true) {
// parsing the user profile information
JSONObject profileObj = responseObj.getJSONObject(response);
String mobile = profileObj.getString("mobile");
PrefManager pref = new PrefManager(getApplicationContext());
pref.createLogin(mobile);
Intent intent = new Intent(HttpService.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Toast.makeText(getApplicationContext(), "HTTPIF"+status, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "HTTPELSE"+status, Toast.LENGTH_LONG).show();
}
} catch (JSONException e) { //------this is working and give toast----//
System.out.print("jsonError :=>"+e);
Toast.makeText(getApplicationContext(),
"Error is WWW: " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "HTTPError: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_SHORT).show();
}
}) {
MyApplication userinfo = (MyApplication)getApplicationContext();
final String user = userinfo.getuser(); // Global Variable get Value uID
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("akey","xxxxxxxxxx");
params.put("mobileverify", otp);
params.put("uid",user);
Log.e(TAG, "Posting params: " + params.toString());
return params;
}
};
MyApplication.getInstance().addToRequestQueue(strReq);
}
【问题讨论】:
标签: android try-catch android-volley