seinecle seinecle - 2 months ago 19
Java Question

"String cannot be converted to CharSequence" all over the place in a Java project?

I reopen a project which was compiling and running fine, and I get errors:


"String cannot be converted to CharSequence"


on all lines that involve String operations, like:

String status = "blah blah";
int countArobase = StringUtils.countMatches(status, "@");
// error "String cannot be converted to CharSequence" at the "@" String.


Note:
StringUtils
comes from
org.apache.commons.lang3.StringUtils


Same error with native methods, like:

String feature;
boolean test = feature.contains("blah blah");
// error "String cannot be converted to CharSequence" at the "blah blah" String.


It is so strange that I'd almost suspect a problem with the IDE? (I use NetBeans 8.0.2)

Answer

Have you checked the JDK & JRE version being used to build the project in NetBeans?

If you are getting problem at compile time, please check your JDK otherwise check your JRE.

If you are using some build tool, check the JDK being used for build tool and -source and -target for the Java compiler.