That's because the Integer#parseInt(String)
method takes in a String
and not a char
. To get the numeric value from a char, use the Character#getNumericValue(char)
.
int pp = Character.getNumericValue(p);
int bp = Character.getNumericValue(b);
Pregunta
I get the following error
Driver.java:237: cannot find symbol
symbol : method parseInt(char)
location: class java.lang.Integer
int bp = Integer.parseInt(b);
when using this code
char p = switchchar.charAt(6);
char b = switchchar.charAt(7);
int pp = Integer.parseInt(p);
int bp = Integer.parseInt(b);
In the documentation it says the method should be there?
Solución
That's because the Integer#parseInt(String)
method takes in a String
and not a char
. To get the numeric value from a char, use the Character#getNumericValue(char)
.
int pp = Character.getNumericValue(p);
int bp = Character.getNumericValue(b);
Otros consejos
You have to turn the char into a String before parseInt will accept it.
The parseInt method receives a String as its parameter, not a char, so you have to do something like this:
String p = "" + switchchar.charAt(6);
String b = "" + switchchar.charAt(7);
int pp = Integer.parseInt(p);
int bp = Integer.parseInt(b);