0

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?

0

3 Answers 3

2

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);
Sign up to request clarification or add additional context in comments.

1 Comment

Oh, how didn't I notice that... Thank you!
2

You have to turn the char into a String before parseInt will accept it.

Comments

1

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.