为什么会出现numberFormatException

sunpro518 2015-04-03 06:50:30
我在给listView的图片准备资源的时候,写了如下代码:
for(int i = 0; i < goodsLength; i++) {
String sb = "cla_" + String.valueOf(i + 1);
goodsClaPic[i] = resourses.getIdentifier(
sb, "drawable", packageName);
}
结果运行到这,总是跳到下面的函数去:
private static NumberFormatException invalidInt(String s) {
throw new NumberFormatException("Invalid int: \"" + s + "\"");
}
这是为什么呢?
...全文
527 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunpro518 2015-06-22
  • 打赏
  • 举报
回复
引用 9 楼 windfury_plus的回复:
[quote=引用 8 楼 dalor 的回复:] 都别扯可好,可用过? 你看到源码上把那个异常打印出来了?抛出来了?没看到Ignore啊。 这个方法的作用本身就是通过文件名查到资源id的。还说得像真的一样。 你把异常信息贴出来。就你那样的描述,不清楚。
兄弟,话能好好说么? 这个问题是为什么打断点会跑到 private static NumberFormatException invalidInt(String s) { throw new NumberFormatException("Invalid int: \"" + s + "\""); } 没说崩溃啊 你自己debug用f5跟一下,就是因为return Integer.parseInt(name); 才进去的![/quote] 原来这样
蚂蚁打dota 2015-04-16
  • 打赏
  • 举报
回复
引用 6 楼 inquisitive_plus 的回复:
[quote=引用 5 楼 sunjinshengli 的回复:]
引用
resourses.getIdentifier这个方法是干嘛的
从drawable调用资源的方法!
你去看源码……

    public int getIdentifier(String name, String defType, String defPackage) {
        if (name == null) {
            throw new NullPointerException("name is null");
        }
        try {
            return Integer.parseInt(name);
        } catch (Exception e) {
            // Ignore
        }
        return mAssets.getResourceIdentifier(name, defType, defPackage);
    }
第一个参数会调用 Integer.parseInt(name); 所以就抛出异常了NumberFormatException[/quote] name中含有非数字吧
开发者_android 2015-04-16
  • 打赏
  • 举报
回复
引用 13 楼 inquisitive_plus 的回复:
[quote=引用 11 楼 dalor 的回复:] 能进? NumberFormatException里调用的方法forInputString,没有方法叫invalidInt。 我能说,这个方法可能是他自己定义的吗?
你打下断点, 我的调试结果是Integer.class的374行throw invalidInt(string);进入的 就会进入Integer.class的第136行 private static NumberFormatException invalidInt(String s) { throw new NumberFormatException("Invalid int: \"" + s + "\""); } 再者,Integer.parseInt转非纯数字本身产生的异常也是NumberFormatException 不调试也能知道[/quote] 好吧,至于进入这个方法否,我的确只关注最终NumberFormatException。没进是我说有不对。 可是,算,没可是,人家求解决问题,我俩扯的远了。
windfury_plus 2015-04-16
  • 打赏
  • 举报
回复
引用 11 楼 dalor 的回复:
能进? NumberFormatException里调用的方法forInputString,没有方法叫invalidInt。 我能说,这个方法可能是他自己定义的吗?
你打下断点, 我的调试结果是Integer.class的374行throw invalidInt(string);进入的 就会进入Integer.class的第136行 private static NumberFormatException invalidInt(String s) { throw new NumberFormatException("Invalid int: \"" + s + "\""); } 再者,Integer.parseInt转非纯数字本身产生的异常也是NumberFormatException 不调试也能知道
开发者_android 2015-04-16
  • 打赏
  • 举报
回复
引用 9 楼 inquisitive_plus 的回复:
[quote=引用 8 楼 dalor 的回复:] 都别扯可好,可用过? 你看到源码上把那个异常打印出来了?抛出来了?没看到Ignore啊。 这个方法的作用本身就是通过文件名查到资源id的。还说得像真的一样。 你把异常信息贴出来。就你那样的描述,不清楚。
兄弟,话能好好说么? 这个问题是为什么打断点会跑到 private static NumberFormatException invalidInt(String s) { throw new NumberFormatException("Invalid int: \"" + s + "\""); } 没说崩溃啊 你自己debug用f5跟一下,就是因为return Integer.parseInt(name); 才进去的![/quote] 另外,坛主,我是引用你楼下滴那个,结果把你的引进了。。。失误失误
开发者_android 2015-04-16
  • 打赏
  • 举报
回复
引用 9 楼 inquisitive_plus 的回复:
[quote=引用 8 楼 dalor 的回复:] 都别扯可好,可用过? 你看到源码上把那个异常打印出来了?抛出来了?没看到Ignore啊。 这个方法的作用本身就是通过文件名查到资源id的。还说得像真的一样。 你把异常信息贴出来。就你那样的描述,不清楚。
兄弟,话能好好说么? 这个问题是为什么打断点会跑到 private static NumberFormatException invalidInt(String s) { throw new NumberFormatException("Invalid int: \"" + s + "\""); } 没说崩溃啊 你自己debug用f5跟一下,就是因为return Integer.parseInt(name); 才进去的![/quote] 能进? NumberFormatException里调用的方法forInputString,没有方法叫invalidInt。 我能说,这个方法可能是他自己定义的吗?
开发者_android 2015-04-16
  • 打赏
  • 举报
回复
引用 9 楼 inquisitive_plus 的回复:
[quote=引用 8 楼 dalor 的回复:] 都别扯可好,可用过? 你看到源码上把那个异常打印出来了?抛出来了?没看到Ignore啊。 这个方法的作用本身就是通过文件名查到资源id的。还说得像真的一样。 你把异常信息贴出来。就你那样的描述,不清楚。
兄弟,话能好好说么? 这个问题是为什么打断点会跑到 private static NumberFormatException invalidInt(String s) { throw new NumberFormatException("Invalid int: \"" + s + "\""); } 没说崩溃啊 你自己debug用f5跟一下,就是因为return Integer.parseInt(name); 才进去的![/quote] 好吧,我承认不够淡定了。 不过, try { return Integer.parseInt(name); } catch (Exception e) { // Ignore } debug能进 private static NumberFormatException invalidInt(String s) { throw new NumberFormatException("Invalid int: \"" + s + "\""); }? 求图。
引用 9 楼 inquisitive_plus 的回复:
[quote=引用 8 楼 dalor 的回复:] 都别扯可好,可用过? 你看到源码上把那个异常打印出来了?抛出来了?没看到Ignore啊。 这个方法的作用本身就是通过文件名查到资源id的。还说得像真的一样。 你把异常信息贴出来。就你那样的描述,不清楚。
兄弟,话能好好说么? 这个问题是为什么打断点会跑到 private static NumberFormatException invalidInt(String s) { throw new NumberFormatException("Invalid int: \"" + s + "\""); } 没说崩溃啊 你自己debug用f5跟一下,就是因为return Integer.parseInt(name); 才进去的![/quote] 能进? NumberFormatException里调用的方法forInputString,没有方法叫invalidInt。 我能说,这个方法可能是他自己定义的吗?
windfury_plus 2015-04-16
  • 打赏
  • 举报
回复
引用 8 楼 dalor 的回复:
都别扯可好,可用过? 你看到源码上把那个异常打印出来了?抛出来了?没看到Ignore啊。 这个方法的作用本身就是通过文件名查到资源id的。还说得像真的一样。 你把异常信息贴出来。就你那样的描述,不清楚。
兄弟,话能好好说么? 这个问题是为什么打断点会跑到 private static NumberFormatException invalidInt(String s) { throw new NumberFormatException("Invalid int: \"" + s + "\""); } 没说崩溃啊 你自己debug用f5跟一下,就是因为return Integer.parseInt(name); 才进去的!
开发者_android 2015-04-16
  • 打赏
  • 举报
回复
引用 6 楼 inquisitive_plus 的回复:
[quote=引用 5 楼 sunjinshengli 的回复:]
引用
resourses.getIdentifier这个方法是干嘛的
从drawable调用资源的方法!
你去看源码……

    public int getIdentifier(String name, String defType, String defPackage) {
        if (name == null) {
            throw new NullPointerException("name is null");
        }
        try {
            return Integer.parseInt(name);
        } catch (Exception e) {
            // Ignore
        }
        return mAssets.getResourceIdentifier(name, defType, defPackage);
    }
第一个参数会调用 Integer.parseInt(name); 所以就抛出异常了NumberFormatException[/quote]
引用 7 楼 nhlbengbeng 的回复:
[quote=引用 6 楼 inquisitive_plus 的回复:] [quote=引用 5 楼 sunjinshengli 的回复:]
引用
resourses.getIdentifier这个方法是干嘛的
从drawable调用资源的方法!
你去看源码……

    public int getIdentifier(String name, String defType, String defPackage) {
        if (name == null) {
            throw new NullPointerException("name is null");
        }
        try {
            return Integer.parseInt(name);
        } catch (Exception e) {
            // Ignore
        }
        return mAssets.getResourceIdentifier(name, defType, defPackage);
    }
第一个参数会调用 Integer.parseInt(name); 所以就抛出异常了NumberFormatException[/quote] name中含有非数字吧[/quote] 都别扯可好,可用过? 你看到源码上把那个异常打印出来了?抛出来了?没看到Ignore啊。 这个方法的作用本身就是通过文件名查到资源id的。还说得像真的一样。 你把异常信息贴出来。就你那样的描述,不清楚。
windfury_plus 2015-04-14
  • 打赏
  • 举报
回复
引用 5 楼 sunjinshengli 的回复:
引用
resourses.getIdentifier这个方法是干嘛的
从drawable调用资源的方法!
你去看源码……

    public int getIdentifier(String name, String defType, String defPackage) {
        if (name == null) {
            throw new NullPointerException("name is null");
        }
        try {
            return Integer.parseInt(name);
        } catch (Exception e) {
            // Ignore
        }
        return mAssets.getResourceIdentifier(name, defType, defPackage);
    }
第一个参数会调用 Integer.parseInt(name); 所以就抛出异常了NumberFormatException
sunpro518 2015-04-13
  • 打赏
  • 举报
回复
引用
resourses.getIdentifier这个方法是干嘛的
从drawable调用资源的方法!
windfury_plus 2015-04-06
  • 打赏
  • 举报
回复
NumberFormatException 是数字格式化异常,你看下那里是不是把一个非纯数字的格子尝试转换成数字?
windfury_plus 2015-04-06
  • 打赏
  • 举报
回复
引用 3 楼 sunjinshengli 的回复:
我是想把他们转换成字符串啊,没有要转换成数字啊!??
resourses.getIdentifier这个方法是干嘛的
sunpro518 2015-04-06
  • 打赏
  • 举报
回复
我是想把他们转换成字符串啊,没有要转换成数字啊!??
sunpro518 2015-04-04
  • 打赏
  • 举报
回复
求大神解答啊!!

80,350

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧