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

标签 java android list arraylist int

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

类(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/

相关文章:

java - Android Studio : Using radioButtons for a quiz

java - Java 和 C++ 运算符之间有什么区别吗?

android - 从android数据库中删除一行

android - 从 Fragment 获取 Activity 中的 Adapter

python - 根据对象属性唯一化对象列表的最快方法

Java - 在巨型列表中追加和删除的最佳策略?

java - 不使用日历和日期实例显示星期几

java - 执行 POST HTTP 方法时, "Response.status(Status.CREATED)"被 eclipse 识别为类型 "Response"未定义

android - 如何添加安装我自己的 LocationProvider?

c# - 跟踪对象的关系列表的最佳方法是什么