【发布时间】:2015-04-08 13:04:40
【问题描述】:
我是 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 = new URL(myurl);”处停止
事件日志消息:“ConcurrentModificationException:null”
你知道这个问题的原因吗?
(对不起我的英语^^')
感谢您的帮助。
【问题讨论】:
-
是否只在调试模式下出现?
-
在 google 上查看网络服务教程。
-
是的,我的方法在我单击按钮时被调用。当我运行我的应用程序时,该按钮什么也不做,而他应该在 listView 上添加数据。
-
你能访问这个吗?然后发布输出。
标签: java android json web-services url