只要fb_flag为1,就在Listener中获取错误,m只是初学者;学习排球
NullPointerException ::: 试图解决错误;但是无法解决它
LoginCall.java
public class Login_Call {
Context con;
String email ="", pass = "";
String fb_flag = String.valueOf(0);
String URL = "";
UserData userData;
String Message = "Success";
用于设置数据项的构造函数;
public Login_Call(Context context, String email, String password, String flag) {
con = context;
this.email = email;`enter code here`
pass = password;
fb_flag = flag;
Toast.makeText(con,fb_flag, Toast.LENGTH_SHORT).show();
}
public UserData getUserDataObject() {
return userData;
}
在此方法中出错; 方法用于使用url;
映射字符串数据 public String getLoginAcc() {
RequestQueue queue = Volley.newRequestQueue(con);
StringRequest postRequest = new StringRequest(Method.POST, URL, new Listener<String>() {
@Override
public void onResponse(String s) {
Log.d("LoginCheck", s);
Toast.makeText(con,s, Toast.LENGTH_SHORT).show();
authenticateLoginResponse(s);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
Toast.makeText(con, "Server Not Responding" + volleyError, Toast.LENGTH_SHORT).show();
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("fb_flag", fb_flag);
params.put("email", email);
params.put("password", pass);
return params;
}
};
postRequest.setTag("Publiko Login");
postRequest.setRetryPolicy(new DefaultRetryPolicy(5000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
queue.add(postRequest);
return Message;
}
private void authenticateLoginResponse(String data) {
String response;
try {
JSONObject responseObject = new JSONObject(data);
response = responseObject.getString("response");
if (response.equals("success")) {
// ToDo succes response Login Acces Granted
JSONArray responseArray = responseObject.getJSONArray("data");
JSONObject reponseInnerObject = responseArray.getJSONObject(0);
UserData user = new UserData();
user.setUsername(reponseInnerObject.getString("user_name"));
user.setEmail(reponseInnerObject.getString("email"));
user.setAddress(reponseInnerObject.getString("address"));
user.setPhone(reponseInnerObject.getString("phone"));
user.setUserid(reponseInnerObject.getString("user_id"));
userData = user;
} else {
// ToDo Failed Response Invalid Email/Password
this.Message = responseObject.getString("message");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
提前感谢:)
答案 0 :(得分:0)
仔细检查您的网址,看看它是否是有效的网址。在我的情况下,我错过了基本网址。