2015-10-26 68 views
0

當我想在一個類中創建一個userLogin方法我想設置一個字符串值,如果成功==「真」,但是當我使方法onResponse和onErrorListener無效它給出了錯誤:不能使方法void

'onErrorResponse('VolleyError') in Anonymous class derived from com.android.volley.Response.ErrorListener' clashes with 'onErrorResponse(VolleyError)' in 'com.android.volley.Response.ErrorListener'; attempting to use incompatible return type'

我的代碼:

private void userLogin() { 
      RequestQueue requestQueue = MySingleton.getInstance().getrequestqueue(); 
      StringRequest stringRequest = new StringRequest(Request.Method.POST, LOGIN_URL, 
        new Response.Listener<String>() { 
         @Override 
         public void onResponse(String response) throws JSONException { 
          checkLogin(response); 
          if(success.equals("true")){ 
           Login.testt = "signed in!"; 
          } 
          else { 
           Login.testt = "error!"; 
          } 
         } 
        }, 
        new Response.ErrorListener() { 
         @Override 
         public void onErrorResponse(VolleyError error) { 
          Login.testt = "error!"; 
         } 
        }) { 
       @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.add(stringRequest); 
     } 

如何使用這些方法爲無效?

回答

2

Overriden方法無法編輯。顧名思義,它們只能被覆蓋

+1

嗯,它們可以被重載,但重載或重載方法的返回類型不能不同。只是要完成。 – Qix