domingo, 14 de octubre de 2012

Error cannot convert from int to CharSequence


The problem:


When I want to get the string value from the class R to a CharSequence type variable like this...
 CharSequence contentTitle = R.string.value;
.. I get Error cannot convert from int to CharSequence. 
String s = R.string.value + "";
CharSequence contentTitle = s;


The solution:


R.string.value is a call to the static field in the class R, which is auto generated by Eclipse and which does a kind of summary of all your resources. To retrieve the string, you need to use :
CharSequence contentTitle = getString(R.string.value);
If you open the R class you will see that it contains only numbers that are references to the compiled resources of your project.

No hay comentarios:

Publicar un comentario