gpt4 book ai didi

java - Integer.parseInt 返回错误 : The method parseInt(String) in the type Integer is not applicable for the arguments (R. 字符串)

转载 作者:行者123 更新时间:2023-12-01 23:39:39 28 4
gpt4 key购买 nike

我必须构建一个由我构建的一些结构组成的数组:

类(Item)的构建方式如下:(如下所示)

现在我的问题是我试图将从另一个地方(在本例中为列表)获取的一些字符串数字解析为 int。

但我收到此错误:

The method parseInt(String) in the type Integer is not applicable for the arguments (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;
}

最佳答案

更改您的代码, 使用 String 插入字符串。

 private int id;

private String title;

private String desc;

private String pub;

private int p;

private int n;

同时更改列表

List<List<String>> items;

关于java - Integer.parseInt 返回错误 : The method parseInt(String) in the type Integer is not applicable for the arguments (R. 字符串),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18161144/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com