我正在使用android Volley连接到服务器.stringRequest POST用于执行相同的操作
StringRequest strReq = new StringRequest(Method.POST,
AppConfig.URL_LOGIN, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, "Login Response: " + response.toString());
hideDialog();
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Login Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_LONG).show();
hideDialog();
}
}) {
@Override
protected Map<String, String> getParams() {
// Posting parameters to login url
Map<String, String> params = new HashMap<String, String>();
params.put("email", email);
params.put("password", password);
Log.e(TAG,email+password);
return params;
}
};
// Adding request to request queue
AppController.getInstance().addToRequestQueue(strReq,tag_string_req);
}
但是当我点击按钮
时,它会显示以下logcat错误FATAL EXCEPTION: main Process: com.baellife.test.baellife, PID: 5285 java.lang.NullPointerException: Attempt to invoke virtual method 'void com.baellife.test.baellife.AppController.addToRequestQueue(com.android.volley.Request, java.lang.String)' on a null object reference
at com.baellife.test.baellife.LoginActivity.checkLogin(LoginActivity.java:185) at com.baellife.test.baellife.LoginActivity.access$200(LoginActivity.java:32) at com.baellife.test.baellife.LoginActivity$1.onClick(LoginActivity.java:80) at android.view.View.performClick(View.java:5204) at android.view.View$PerformClick.run(View.java:21153) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
中似乎是strReq
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
返回NULL。