在android按钮上调用方法单击

在android按钮上调用方法单击,android,button,methods,call,Android,Button,Methods,Call,我正在尝试通过android按钮点击来调用web服务。我已经设法纠正了错误,但在得到响应时显示了一些错误。我收到null响应。下面是我的代码。有人能帮我调试一下吗 我的代码: refresh\u btn.setOnClickListener(新的OnClickListener(){ @凌驾 公共void onClick(视图v){ HttpHandler httpHandler1=新的HttpHandler(); 字符串res=null; 字符串authToken=“MlSyULrWlFgVk2

我正在尝试通过android按钮点击来调用web服务。我已经设法纠正了错误,但在得到响应时显示了一些错误。我收到
null
响应。下面是我的代码。有人能帮我调试一下吗

我的代码:
refresh\u btn.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
HttpHandler httpHandler1=新的HttpHandler();
字符串res=null;
字符串authToken=“MlSyULrWlFgVk28”;
试一试{
Log.d(“edwLog”,TAG+“get_payment_notifications”+HttpHandler.API_URL+“get_payment_notifications/”+authToken+“/”);
res=httpHandler1.makeServiceCall(HttpHandler.API_URL+“获取支付通知/”+authToken+“/”,HttpHandler.get);
Log.d(“edwLog”,标记+“响应>”+res);
如果(res!=null){
JSONObject JSONObject=新的JSONObject(res);
String responseType=jsonObject.getString(“类型”);
if(responseType.equals(“success”)){
if(jsonObject.has(“response”)){
JSONArray JSONArray=jsonObject.getJSONArray(“响应”);
for(int i=0;i”+e.toString());
}
}
});

您是否遇到编译时错误或运行时错误。似乎您正试图从返回类型为void的方法返回bundle,即

    public void onClick(View v)

找到了错误。。!错误是,我将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());
            }
        }
    });
refresh\u btn.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
HttpHandler httpHandler1=新的HttpHandler();
字符串res=null;
试一试{
Log.d(“edwLog”,TAG+“get_payment_notifications”+HttpHandler.API_URL+“get_payment_notifications/”+AuthToken+“/”);
res=httpHandler1.makeServiceCall(HttpHandler.API_URL+“获取支付通知/”+AuthToken+“/”,HttpHandler.get);
Log.d(“edwLog”,标记+“响应>”+res);
如果(res!=null){
JSONObject JSONObject=新的JSONObject(res);
String responseType=jsonObject.getString(“类型”);
if(responseType.equals(“success”)){
if(jsonObject.has(“response”)){
JSONArray JSONArray=jsonObject.getJSONArray(“响应”);
for(int i=0;i”+e.toString());
}
}
});

logcat log在哪里?这到底是什么意思<代码>最终捆绑结果=新捆绑();返回结果结果什么都不是!是的,这就是我所震惊的Skizo..应该返回什么结果?@vinaysam这不是Logcat错误日志:(那么我到底应该怎么做Bhushan?你能帮我编辑代码吗?下面是我的必要回答:==============================================================================可能的回答:不正确的令牌:{“类型”:“错误”,“消息”:“安全令牌丢失”。}无付款通知:{“类型”:“错误”,“消息”:“无付款通知”}成功:{“类型”:“成功”,“响应”:{[notification array]}您可以在该块本身中执行所需的操作,而不是返回某些内容。另外,您尝试创建的bundle对象的用途是什么。因为它似乎只是一个没有任何数据的新对象。
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());
            }
        }
    });