If I try
nltxt = nllen.toString();
with nllen
being
int nllen = nl.getLength();
I get the error
Cannot invoke
toString()
on the primitive type int.
I want to convert the int to string so i can display the number of entries with Log... Why doesn't it work?
Primitives do not have any fields or methods. Sometimes the compiler will "autobox" your primitive into the corresponding class, Integer
in this case. Perhaps that is what you expected in this case. Sometimes the compiler will not do this. In this case it does not automatically autobox it.
You have a few alternatives:
String.valueOf(nltxt)
"" + nltxt
(or if you have something useful to write along with the number, do "nltxt equals " + nltxt
Do the "autoboxing" manually: new Integer(nltxt).toString()
.
Format it in some custom way: String.format("nltxt is %d which is bad%n", nltxt)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With