• Android错误:W/ResourceType(2411): No package identifier when getting value for resource number 0x


    报错信息:

    07-04 11:14:43.064: W/ResourceType(2411): No package identifier when getting value for resource number 0x0000001c
    07-04 11:14:43.064: W/System.err(2411): android.content.res.Resources$NotFoundException: String resource ID #0x1c

    错误位置示例代码:

     int percent = current * 100 / total;
    textView1.setText(percent);

    原因分析:

    主要原因是TextView的setText方法把传入的int类型的percent当做资源Id到项目中查询资源,而资源中却找不到相应的数值,就会报NotFoundException的错误。

    在Android中利用id来索引资源的地方很多(如:Toast.makeText()等),所以如果不小心往方法中传入int类型的参数,虽然编译时IDE不会报错,但是运行时,很容易因找不到对应的资源而报错。

    解决办法:

    所以如果要在TextView中显示int类型的数据,应提前转换成字符串类型。转换方法很多,最简单的就是在int类型数据后加上一个空字符串,如:

    textView1.setText(percent+"");

    参考:http://blog.csdn.net/wangfayinn/article/details/7716165

    态度决定高度,细节决定成败,
  • 相关阅读:
    Jenkins学习记录(三)
    Jenkins学习记录(二)
    并发编程
    黏包及解决方法
    socket通信,三次握手,四次挥手
    异常处理
    元类与魔法方法
    封装方法与多态
    组合与封装
    继承
  • 原文地址:https://www.cnblogs.com/lxk2010012997/p/4009843.html
Copyright © 2020-2023  润新知