I want to convert a int to String in java but I can't :
this is the code I used :
jTextField1.setText((String)l.getCode());
and this is the error I got :
Inconvertible types
required:java.lang.String
found: int
I want to convert a int to String in java but I can't :
this is the code I used :
jTextField1.setText((String)l.getCode());
and this is the error I got :
Inconvertible types
required:java.lang.String
found: int
You can not typecast int
to string
try below code.
jTextField1.setText(String.valueOf(l.getCode()));
Use
Integer.toString(l.getCode);
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Integer.html#toString%28int%29
Try something like this:
Integer.valueOf(l.getCode()).toString()
You cannot convert int
simple type to String
object.
This should be what you are looking for:
jTextField1.setText(String.valueOf(l.getCode()))
jTextField1.setText(String.valueOf(l.getCode()));
There are three ways you convert an integer to string firstly using the built-in converter,
jTextField1.setText("" + l.getCode())
Secondly you could use the static method toString(int) of the Integer class,
jTextField1.setText(Integer.toString(l.getCode()))
You could also use a formatter but this in not recommended as it just makes the code cumbersome and difficult to understand.
jTextField1.setText(String.format("%d", l.getCode()))