public void newUser(final String name, final String email, final String password){
String tag_string_req = "req_register";
pDialog.setMessage("Registrando...");
pDialog.show();
StringRequest strReq = new StringRequest(Request.Method.POST, AppConfig.url_register,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, "Register response: " + response.toString());
pDialog.hide();
try {
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");
if (!error) {
String uid = jObj.getString("uid");
JSONObject user = jObj.getJSONObject("user");
String name = user.getString("name");
String email = user.getString("email");
db.addUser(name, email, uid);
Toast.makeText(getApplicationContext(), name + "Hurray!, registrado tente logar agora ^^", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(intent);
finish();
} else {
String errorMsg = jObj.getString("error_msg");
Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Erro no registro: " + error.getMessage());
Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
}
}){
@Override
protected Map<String, String> getParams(){
HashMap<String, String> params = new HashMap<>();
params.put("name", name);
params.put("email", email);
params.put("password", password);
return params;
}
};
MySingleton.getInstance().addToRequestQueue(strReq);
}
所以看起来像params或strReq返回null,我尝试了一个带有JSON的自定义请求我能找到的一切,我在这里读到StackOverflow,getParams()不应该存在或覆盖方法getBody() ,更改并继续返回null,异常java.lang.NullPointerException,谢谢。