我是Android Studio的begginer,我从WebService调用Json时遇到问题。
我用这个代码,试图让我的数据:URL错误:从Android Studio上的WebService获取JSON
public static ArrayList<User> getUsers() {
ArrayList<User> users = new ArrayList<User>();
try {
String myurl = "http://localhost/MyWebService/getUsers";
URL url = new URL(myurl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();
InputStream inputStream = connection.getInputStream();
String result = InputStreamOperations.InputStreamToString(inputStream);
JSONObject jsonObject = new JSONObject(result);
JSONArray array = new JSONArray(jsonObject.getString("UserDB"));
for (int i = 0; i < array.length(); i++) {
JSONObject obj = new JSONObject(array.getString(i));
User user = new User(obj.getString("name"), obj.getString("firstname"));
users.add(user);
}
} catch (Exception e) {
e.printStackTrace();
}
return users;
}
但在调试国防部,它停在 “URL网址=新的URL(myurl);”
事件日志消息:“ConcurrentModificationException:null”
请问您有关于此问题的原因的想法吗? (对不起我的英语^^')
感谢您的帮助。
它仅在调试模式下发生吗? – Ilya
查看Google上的Web服务教程。 – Shvet
是的,当我点击一个按钮时,我的方法被调用。 当我运行我的应用程序时,该按钮什么都不做,而他应该在listView上添加数据。 – Drooka