2015-07-13 96 views
-1

我正在嘗試通過android button click進行web服務調用。我已經設法糾正錯誤,但它顯示了一些錯誤獲得迴應。我收到null迴應。以下是我的代碼。有人可以調試我請.. ..!提前致謝。調用android按鈕單擊方法

我的代碼:

refresh_btn.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 

      HttpHandler httpHandler1 = new HttpHandler(); 
      String res = null; 
      String authToken = "MlSyULrWlFgVk28"; 

      try { 

       Log.d("edwLog", TAG + " get_payment_notifications " + HttpHandler.API_URL + "get_payment_notifications/" + authToken + "/"); 
       res = httpHandler1.makeServiceCall(HttpHandler.API_URL + "get_payment_notifications/" + authToken + "/", HttpHandler.GET); 
       Log.d("edwLog", TAG + " response > " + res); 
       if (res != null) { 
        JSONObject jsonObject = new JSONObject(res); 
        String responseType = jsonObject.getString("type"); 
        if (responseType.equals("success")) { 
         if (jsonObject.has("response")) { 

          JSONArray jsonArray = jsonObject.getJSONArray("response"); 
          for (int i = 0; i < jsonArray.length(); i++) { 
           notifications.add(jsonArray.getJSONObject(i)); 
          } 
         } 
        } 
       } 

      } catch (Exception e) { 
       e.printStackTrace(); 
       Log.d("edwLog", TAG + " IOException > " + e.toString()); 
      } 
     } 
    }); 
+1

logcat log在哪裏? –

+0

這究竟是什麼? :'final Bundle result = new Bundle(); 返回結果;'結果是沒有! –

+0

是的,這就是我觸及Skizo .. – sam

回答

0

找到了這個錯誤..!錯誤是,我已經通過AuthToken作爲默認字符串。現在,我在final中將它聲明爲「null」,即在onCreate之前將其從ClickEvent中刪除。它的完成..以下正確的代碼..

refresh_btn.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 

      HttpHandler httpHandler1 = new HttpHandler(); 
      String res = null; 


      try { 

       Log.d("edwLog", TAG + " get_payment_notifications " + HttpHandler.API_URL + "get_payment_notifications/" + AuthToken + "/"); 
       res = httpHandler1.makeServiceCall(HttpHandler.API_URL + "get_payment_notifications/" + AuthToken + "/", HttpHandler.GET); 
       Log.d("edwLog", TAG + " response > " + res); 
       if (res != null) { 
        JSONObject jsonObject = new JSONObject(res); 
        String responseType = jsonObject.getString("type"); 
        if (responseType.equals("success")) { 
         if (jsonObject.has("response")) { 

          JSONArray jsonArray = jsonObject.getJSONArray("response"); 
          for (int i = 0; i < jsonArray.length(); i++) { 
           notifications.add(jsonArray.getJSONObject(i)); 
          } 
         } 
        } 
       } 

      } catch (Exception e) { 
       e.printStackTrace(); 
       Log.d("edwLog", TAG + " IOException > " + e.toString()); 
      } 
     } 
    }); 
2

您是否收到編譯時錯誤或運行時。看來你試圖從返回類型爲void的方法返回一個包,即

public void onClick(View v) 
+0

那麼我應該怎麼做Bhushan?你能爲我編輯代碼嗎? 下面給出的是我的必要回應: =========== ====================== 可能的迴應: 令牌不正確: {「type」:「error」,「msg」:「安全令牌丟失。 「} 沒有付款通知: {」type「:」error「,」msg「:」沒有付款通知「} 成功: {」type「:」success「,」response「:{[notification array]} } – sam

+1

而不是返回的東西,你可以執行你需要在該塊本身的操作。還有什麼是你使用捆綁對象試圖創造。因爲它似乎只是一個沒有任何數據的新對象。 – Bhushan

+0

如果我解決了您的問題,您是否可以將此答案標記爲已接受。那太好了 :) – Bhushan