为什么我不能将String转换为Integer

时间:2013-04-15 18:54:46

标签: java android

我知道这是一个容易的话题,但我总是得到错误..我从xml文件中获取数据包含的字符串,如262626我试图将此字符串转换为MB(/ 1024)表单。但它没有转换为int或long可以有人帮助我吗?

这是我测试的内容

String size = parser.getValue(e, parser.KEY_FileSizeInByte);
Log.i("menuItems",size);

    try {
        int s = Integer.parseInt(size);
        Log.i("s", getString(s));
    }
    catch (Exception e1) {
        Log.i("error", e1.getMessage());
    }

我也测试了

Integer.valueOf(str); 

这是我收到的错误:

04-15 23:06:17.652: I/menuItems(6819): 97035
04-15 23:06:17.652: W/ResourceType(6819): No package identifier when getting value for resource number 0x00017b0b
04-15 23:06:17.652: I/error(6819): String resource ID #0x17b0b
04-15 23:06:17.692: I/menuItems(6819): 2957
04-15 23:06:17.692: W/ResourceType(6819): No package identifier when getting value for resource number 0x00000b8d
04-15 23:06:17.692: I/error(6819): String resource ID #0xb8d
04-15 23:06:17.692: I/menuItems(6819): 559711
04-15 23:06:17.692: W/ResourceType(6819): No package identifier when getting value for resource number 0x00088a5f
04-15 23:06:17.692: I/error(6819): String resource ID #0x88a5f
04-15 23:06:17.692: I/menuItems(6819): 153651
04-15 23:06:17.692: W/ResourceType(6819): No package identifier when getting value for resource number 0x00025833
04-15 23:06:17.692: I/error(6819): String resource ID #0x25833
04-15 23:06:17.692: I/menuItems(6819): 1733630
04-15 23:06:17.692: W/ResourceType(6819): No package identifier when getting value for resource number 0x001a73fe
04-15 23:06:17.692: I/error(6819): String resource ID #0x1a73fe
04-15 23:06:17.692: I/menuItems(6819): 532105
04-15 23:06:17.692: W/ResourceType(6819): No package identifier when getting value for resource number 0x00081e89
04-15 23:06:17.692: I/error(6819): String resource ID #0x81e89
04-15 23:06:17.702: I/menuItems(6819): 28817
04-15 23:06:17.702: W/ResourceType(6819): No package identifier when getting value for resource number 0x00007091
04-15 23:06:17.702: I/error(6819): String resource ID #0x7091
04-15 23:06:17.702: I/menuItems(6819): 90787
04-15 23:06:17.702: W/ResourceType(6819): No package identifier when getting value for resource number 0x000162a3
04-15 23:06:17.702: I/error(6819): String resource ID #0x162a3
04-15 23:06:17.702: I/menuItems(6819): 33556
04-15 23:06:17.702: W/ResourceType(6819): No package identifier when getting value for resource number 0x00008314
04-15 23:06:17.702: I/error(6819): String resource ID #0x8314
04-15 23:06:17.702: I/menuItems(6819): 122145
04-15 23:06:17.702: W/ResourceType(6819): No package identifier when getting value for resource number 0x0001dd21
04-15 23:06:17.702: I/error(6819): String resource ID #0x1dd21
04-15 23:06:17.702: I/menuItems(6819): 323312
04-15 23:06:17.702: W/ResourceType(6819): No package identifier when getting value for resource number 0x0004eef0
04-15 23:06:17.702: I/error(6819): String resource ID #0x4eef0
04-15 23:06:17.702: I/menuItems(6819): 532676
04-15 23:06:17.702: W/ResourceType(6819): No package identifier when getting value for resource number 0x000820c4
04-15 23:06:17.702: I/error(6819): String resource ID #0x820c4
04-15 23:06:17.712: I/menuItems(6819): 49133
04-15 23:06:17.712: W/ResourceType(6819): No package identifier when getting value for resource number 0x0000bfed
04-15 23:06:17.712: I/error(6819): String resource ID #0xbfed
04-15 23:06:17.712: I/menuItems(6819): 622507
04-15 23:06:17.712: W/ResourceType(6819): No package identifier when getting value for resource number 0x00097fab
04-15 23:06:17.712: I/error(6819): String resource ID #0x97fab
04-15 23:06:17.712: I/menuItems(6819): 57333
04-15 23:06:17.712: W/ResourceType(6819): No package identifier when getting value for resource number 0x0000dff5
04-15 23:06:17.712: I/error(6819): String resource ID #0xdff5
04-15 23:06:17.712: I/menuItems(6819): 17265
04-15 23:06:17.712: W/ResourceType(6819): No package identifier when getting value for resource number 0x00004371
04-15 23:06:17.712: I/error(6819): String resource ID #0x4371

1 个答案:

答案 0 :(得分:6)

这是你的日志错误。这里:

Log.i("s", getString(s));

那是尝试使用给定的标识符获取资源。你只想要:

Log.i("s", String.valueOf(s));