[英]The method parseInt(String) in the type Integer is not applicable for the arguments (boolean)
[英]Integer.parseInt Returns an error: The method parseInt(String) in the type Integer is not applicable for the arguments (R.string)
我必须构建一些已构建的结构的数组:
类(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;
}
您使用的string
类型显然不是java.lang.String
,因此您不能将其作为Integer.parseInt(java.lang.String)
参数。
更改您的代码,使用String插入的字符串。
private int id;
private String title;
private String desc;
private String pub;
private int p;
private int n;
同时更改清单
List<List<String>> items;
在不更改代码的情况下执行此操作的另一种方法是,应在parseInt()中调用getString(),以便getString()将返回java.lang.String,如下所示:
getString(R.string.value);
这样做将节省您string with String.
替换string with String.
大量工作string with String.
如果打开R类,您将看到它仅包含引用项目的已编译资源的数字。
选择是你的:)
干杯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.