ERROR No package identifier when getting value for resource number

廉价感情. 提交于 2019-11-27 14:21:00

I got this same error message when I tried to use TextView.setText passing a char instead of a String. This makes sense since the char would be promoted to an int which meant that I was really calling the

TextView.setText( int resId );

And since there wasn't a resource with that value, it wouldn't work.

楊惟鈞

face with the same error

finally i found its not a error due to your xml layout

somewhere in your code set TextView.setText(int)

try TextView.setText( Integer.toString(int));

Henok

When you pass an integer to the TextView.setText() to be displayed android assumes it is a resource id and that's why you are getting Resource$NotFoundException. Try converting the int to String before passing it to TextView.setText(): TextView.setText(String.valueOf(i)).

Paul

Just for the protocol, You could also use:

TextView.setText("" + intVar) instead of TextView.setText(intVar)

I got the same error while trying to print integer value : TextView.setText(int value). I resolved this error by converting the integer value to string and the i used TextView.setText(converted string value)

I had the same problem before I come to this post. For me, it was like this: view_element.setText( an_int_value). After casting view_element.setText(String.valueOf(an_int_value));, everything is okay.

Lucy Lu

For me I had to go in the XML file for the button. There I noticed a hard coded string value. I had to remove that, and also I had to use Textview.setText("" + intVar);

It is due to typecast error. You have to try this- TextView.setText(Integer.toString(variable_name));

Here toString is used to convert integer to string for showing text.

Rigoberto Torres

From Android TextView Documentation:

  • setText(int resid) Sets the text to be displayed using a string resource identifier.

I was using Picasso library to load image from the network. The urls are in a ArrayList I wasn't using arraylist.get() to get the position of the url in the ArrayList.

I recently had this problem, when i was trying to integrate SocialAuth libray with my Android application with Android Studio. What was my problem was, some of my resources like facebook icon, were in the mipamp folder. I moved it to drawables folder and the issue got fixed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!