Click here to Skip to main content
15,889,838 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am facing a small and silly error which i am not able to find out. in my main class i declared a variable int a=4; now i want to print it in a textview. i wrote the following code
Java
num1=(TextView) findViewById(R.id.textView14);
num1.setText(a);

when i run the program i get an error saying ResourceNotFoundException String ID

what can be the mistake that i have done? please guide me through it
Posted
Comments
Rahul Ramakrishnan 15-Jun-15 5:26am    
ohh i figured it out.
num1.setText(Integer.toString(a));

setText[^] with a single int parameter used to set the text from a resource where the int is the resource id...In your case it will look for the resource with id 4 - which does not exists...
Convert the number to string using .toString() method of the int type...
 
Share this answer
 
Convert the number to string i.e
int num = 5;
String n = num + "";

and then,
num1.setText(n);

-KR
 
Share this answer
 
Hi,

The error means a resource you've used couldn't be found.

Please check that you've created a TextView with the id of textView14.

Lastly, change the line:
Java
num1.setText(a);

to:
Java
num1.setText(a.toString());

This is because TextViews only accept text in form of String.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900