我正在尝试使用PHP文件和JSONObject与我的远程数据库进行连接,但是代码正在滑动Response.Listener,我不知道为什么...... 这里我的Main包含Response.Listener:
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
Toast.makeText(Register.this, "Test00", Toast.LENGTH_SHORT).show();
JSONObject jsonObject = new JSONObject(response);
boolean success = jsonObject.getBoolean("success");
if(success)
{
Toast.makeText(Register.this, "Test01", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(Register.this, "Error", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
RegisterRequest registerRequest = new RegisterRequest(email, username, usernick, password, birthdate, gender, responseListener);
RequestQueue queue = Volley.newRequestQueue(Register.this);
queue.add(registerRequest);
这里是我的RegisterRequest类:
public class RegisterRequest extends StringRequest {
private static final String REGISTER_REQUEST_URL = "kameo.com.br/control/ayzac_control_signin_mobile.php";
private Map<String, String> params;
public RegisterRequest(String email, String name, String nickname, String password, String date, String gender, Response.Listener<String> listener)
{
super(Method.POST, REGISTER_REQUEST_URL, listener, null);
params = new HashMap<>();
params.put("userEmail", email);
params.put("userName", name);
params.put("userNickname", nickname);
params.put("userPassword", password);
params.put("userBirth", date);
params.put("userGender", gender);
}
@Override
public Map<String, String> getParams() {
return params;
}
}
答案 0 :(得分:0)
我测试了您的网址,并且出现了错误:kameo.com.br/control/ayzac_control_signin_mobile.php
此外,您需要从服务器响应中读取错误,尝试创建错误监听器:
Response.Listener<String> errorListener = new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Error : " + error.getMessage());
}
};
并传递给RegisterRequest构造函数