我正在尝试通过 android 按钮点击进行网络服务调用。我已经设法纠正了错误,但它显示了一些关于获得响应的错误。我收到 null
响应。下面是我的代码。有人可以调试我吗..!
我的代码:
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());
}
}
});
最佳答案
您遇到的是编译时错误还是运行时错误。似乎您正在尝试从具有返回类型 void 的方法返回一个包,即
public void onClick(View v)
关于android - 在android按钮上调用方法点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31383960/