我必须构建我已经构建的一些结构的数组:
类(Item)的构建方式如下:(如下图所示)
现在我的问题是我试图解析一些我从另一个地方(在这种情况下是一个列表)到 int 的字符串数字。
但我得到这个错误:
Integer 类型中的方法 parseInt(String) 不适用于参数 (R.string)
这是一段代码:(它说错误在(“Integer.parseInt”)中:
markers.add(new item(Integer.parseInt(items.get(0).get(i)), items.get(1).get(i), items.get(2).get(i), items.get(3).get(i), Integer.parseInt(items.get(4).get(i)), Integer.parseInt(items.get(5).get(i))));
它只是很长,但并不复杂。
非常感谢!
编辑:
项目列表只是列表的列表:
List<List<string>> items;
类的结构是:
private int id;
private string title;
private string desc;
private string pub;
private int p;
private int n;
编码:
public List<List<String>> Download()
{
String data = null;
//String res = "";
try {
client = new DefaultHttpClient();// Reference to the Internet
httppost = new HttpPost(URL);
HttpResponse response = client.execute(httppost);
HttpEntity entity = response.getEntity();// get the content of the
// message
InputStream webs = entity.getContent();
BufferedReader in = new BufferedReader(new InputStreamReader(webs,"iso-8859-1"));
StringBuffer sb = new StringBuffer("");
String l = " ";
// String nl=System.getProperty("line.separator");
while ((l = in.readLine()) != null) {
sb.append(l + "\n");
}
data = sb.toString();
webs.close();
List<List<String>> all= new ArrayList<List<String>>();
all.add(new ArrayList<String>());
all.add(new ArrayList<String>());
all.add(new ArrayList<String>());
all.add(new ArrayList<String>());
all.add(new ArrayList<String>());
all.add(new ArrayList<String>());
all.add(new ArrayList<String>());
try {
JSONObject json = new JSONObject(data);
JSONArray jArray = json.getJSONArray("item");
for (int i = 0; i < jArray.length(); i++) {
JSONObject json_data = jArray.getJSONObject(i);
//res += json_data.getString("title")+"\n";
all.get(0).add(json_data.getString("id"));
}
for (int i = 0; i < jArray.length(); i++) {
JSONObject json_data = jArray.getJSONObject(i);
//res += json_data.getString("title")+"\n";
all.get(0).add(json_data.getString("title"));
}
for (int i = 0; i < jArray.length(); i++) {
JSONObject json_data = jArray.getJSONObject(i);
//res += json_data.getString("title")+"\n";
all.get(0).add(json_data.getString("desc"));
}
for (int i = 0; i < jArray.length(); i++) {
JSONObject json_data = jArray.getJSONObject(i);
//res += json_data.getString("title")+"\n";
all.get(0).add(json_data.getString("pub"));
}
for (int i = 0; i < jArray.length(); i++) {
JSONObject json_data = jArray.getJSONObject(i);
//res += json_data.getString("title")+"\n";
all.get(0).add(json_data.getString("p"));
}
for (int i = 0; i < jArray.length(); i++) {
JSONObject json_data = jArray.getJSONObject(i);
//res += json_data.getString("title")+"\n";
all.get(0).add(json_data.getString("n"));
}
return all;
} catch (JSONException e) {
}
//return news;
} catch (Exception e) {
int x=3;
// TODO: handle exception
}
return null;
}