I have trouble with a little section of my code.
I asked the user to give me an answer (using scanner), and know I want to use that information in other method. Then I want to compare it to see if the answer is correct. Her is a little part of my code:
public void enterYourName(){
System.out.println("What is your name?");
name = input.nextLine();
}
And I want to use this information in another method:
public void check(String personName){
if(name.contentEquals("Eric")){
/* TODO */
}
}
I'm receiving these error messages:
The type
java.lang.CharSequence
cannot be resolved. It is indirectly referenced from required .class files.The method
contentEquals(java.lang.StringBuffer)
in the typejava.lang.String
is not applicable for the arguments (java.lang.String
).
What I am doing wrongly? Also, feel free to correct me if the if the statements are wrong.
java.lang.CharSequence
should be available for you even without any import - it is part of the JDK. It can't be said easily, why it won't work, but it should.- As per its documentation page,
String.contentEquals
can be parametrized by aStringBuffer
or by aCharSequence
. You want to call it by aString
, it won't work.
(2) can be solved very easily:
- As @AndréMartins says in comment, simply you can use
String.equals(...)
orString.equalsIgnoreCase(...)
. - Both
StringBuffer
andCharSequence
classes have atoString()
method, what converts them to aString
.
I also suspect, something might be problematic with the JDK/JRE installation of your machine.