我在本地主机中使用排气连接,并在本地主机中有一个php文件。下面是我的课VolleyConnectionLogin和我也有一个凌空单身类(没有错误)..在“返回检查”时布尔检查的值为空
public class VolleyConnectionLogin {
Context context;
public VolleyConnectionLogin(Context context){
this.context = context;
}
static Boolean check;
public Boolean volleyConnection(final String username , final String password) {
String tag_string_req = "string_req";
String url = "http://192.168.10.8/login/forlogin.php";
StringRequest stringRequest = new StringRequest(Request.Method.POST,
url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, response.toString());
if(response.toString().equals("successful")){
check = true;
}else{
check = false;
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
check = false;
VolleyLog.d(TAG, "Error: " + error.getMessage());
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("uname", username);
params.put("pword", password);
return params;
}
};
VolleySingleton.getInstance(context).addToRequestQueue(stringRequest);
return check;
}
}
'check'变量总是为false,因为您正在使用回调方法'onResponse'方法设置'check'变量的值。 –
使用false来初始化检查,例如'static Boolean check = false;',因为'Boolean'类型的默认值为'null'。 –