1、错误说明
今天在写一个项目的时候,LogCat报的是.Resources$NotFoundException: String resource ID #0x14。当时我还以为是因为我xml布局中的ID值和Java中的findViewById()不一致所造成的。跑过去检查了好久,都没有问题,后来在网上搜索,结果发现了问题。
2、问题解释:这个String resource ID #0x14是一个固定的错误代码,意思是setText()有问题。
3思来想去,setText()中不能输入int类型的数据,setText只能输入String类型的数据。但是,如果真的想在setText()中输入int类型的数据怎么办呢?答案就是加上+""
废话不多说,上代码:
//这是对控件加上的监听
mLifeTV=findViewById(R.id.tv_life_progress);
mAttackTV=findViewById(R.id.tv_attack_progress);
mSpeedTV=findViewById(R.id.tv_speed_progress);
//为setText()赋值
mAttackTV.setText(mProgressBar2.getProgress()+" ");
mLifeTV.setText(mProgressBar1.getProgress()+" ");
mSpeedTV.setText(mProgressBar3.getProgress()+" ");
别忘了+“”