convert to integer?
-
i have this particular line in my program however when i execute this line it gives me error. Integer addIncidentID = (Integer) getIncidentidtxt().getValue(); how do i convert from string to integer?
-
i have this particular line in my program however when i execute this line it gives me error. Integer addIncidentID = (Integer) getIncidentidtxt().getValue(); how do i convert from string to integer?
Of course you can't cast a String to an Integer, they are two completely unrelated types. You have to use the
Integer.valueOff(String s)
method:Integer addIncidentID = Integer.valueOff(getIncidentidtxt().getValue());
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
i have this particular line in my program however when i execute this line it gives me error. Integer addIncidentID = (Integer) getIncidentidtxt().getValue(); how do i convert from string to integer?
this is a static method of the type Integer:
int iValue = Integer.parseInt(givenString);
This one throws an exception when converting fails. So best is to wrap in a try/catch:
int iValue=0; // declared and initialized to a simple value (could be -1 when 0 is used)
try{
iValue = Integer.parseInt(givenString);
}
catch(NumberFormatException oException){
// doShowFunnyPopup();
}regards, Torsten
I never finish anyth...
-
i have this particular line in my program however when i execute this line it gives me error. Integer addIncidentID = (Integer) getIncidentidtxt().getValue(); how do i convert from string to integer?
can i use interger.parseint?
-
can i use interger.parseint?
-
can i use interger.parseint?
Please, check the javadoc ! Yes you can use parseInt but it returns an int, not an Integer. So, depending on your needs, either use valueOf or parseInt.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
i have this particular line in my program however when i execute this line it gives me error. Integer addIncidentID = (Integer) getIncidentidtxt().getValue(); how do i convert from string to integer?
pancakeleh wrote:
how do i convert from string to integer?
you can convert string to integer by using various ways you can use valueOf method of Integer class in this way
Integer obj = Integer.valueOf(str_value); // str_value is your string value
you can use Integer Constructor
Integer obj = new Integer(str_value);
you can use parseInt method
int objt = Integer.parseInt(str_value);
-
i have this particular line in my program however when i execute this line it gives me error. Integer addIncidentID = (Integer) getIncidentidtxt().getValue(); how do i convert from string to integer?
-
i got it. thanks alot.
-
Of course you can't cast a String to an Integer, they are two completely unrelated types. You have to use the
Integer.valueOff(String s)
method:Integer addIncidentID = Integer.valueOff(getIncidentidtxt().getValue());
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++// to primitive int i from Integer Object ii int i = ii.intValue(); // to Integer ii from primitive int i Integer ii = new Integer( i );
-
i have this particular line in my program however when i execute this line it gives me error. Integer addIncidentID = (Integer) getIncidentidtxt().getValue(); how do i convert from string to integer?
int int_page_id=o; String str_page_id="5"; try { int_page_id = Integer.parseInt(str_page_id); } catch(NumberFormatException ex) { ex.printStackTrace(); }
-
i have this particular line in my program however when i execute this line it gives me error. Integer addIncidentID = (Integer) getIncidentidtxt().getValue(); how do i convert from string to integer?
String a="2"; int value = Integer.parseInt(a);