2015-10-23 85 views
1

當我想要做一個POST請求(與凌空libary)在一個名爲checkUserLogin類我在隊列中收到一個錯誤:Android的請求隊列

enter image description here

這是我的代碼:

private boolean request() { 
    StringRequest stringRequest = new StringRequest(Request.Method.POST, LOGIN_URL, 
      new Response.Listener<String>() { 
       @Override 
       public boolean onResponse(String response) throws JSONException { 
        checkLogin(response); 
        if(success.equals("true")){ 
         return true; 
        } 
        else{ 
         return false; 
        } 
       } 
      }, 
      new Response.ErrorListener() { 
       @Override 
       public boolean onErrorResponse(VolleyError error) { 
        return false; 
       } 
      }) { 
     @Override 
     protected Map<String, String> getParams() throws AuthFailureError { 
      Map<String, String> map = new HashMap<String, String>(); 
      map.put(EMAIL, email); 
      map.put(PASSWORD, password); 
      return map; 
     } 
    }; 

    RequestQueue requestQueue = Volley.newRequestQueue(this); 
    requestQueue.add(stringRequest); 
    return false; 
} 

我在做什麼錯我的RequestQueue?

+0

此方法是否寫入子類? (請添加滿堂課) –

回答

0

newRequestQueue的參數是Context對象。如果您收到編譯時錯誤,則表示這不是指Context對象。該文檔建議使用ApplicationContext爲了newRequestQueue(請參閱here)。如果你的班級中沒有可用的上下文,你可以考慮子類化應用程序並實現一個singleton,以便能夠從任何地方進行檢索

+0

謝謝修復問題! – Jamie

+0

不用客氣 – Blackbelt