The type java.lang.CharSequence cannot be resolved in package declaration
Java 8 supports default methods in interfaces. And in JDK 8 a lot of old interfaces now have new default methods. For example, now in CharSequence we have chars and codePoints methods.
If source level of your project is lower than 1.8, then compiler doesn't allow you to use default methods in interfaces. So it cannot compile classes that directly on indirectly depend on this interfaces.
If I get your problem right, then you have two solutions. First solution is to rollback to JDK 7, then you will use old CharSequence interface without default methods. Second solution is to set source level of your project to 1.8, then your compiler will not complain about default methods in interfaces.
Eclipse Error: java.lang.CharSequence cannot be resolved
Ensure that your Eclipse IDE supports Java 8:
The first Eclipse version supporting Java 8 was Eclipse Kepler SR2 (4.3.2) with an additional patch. (See: Installing Java™ 8 Support in Eclipse Kepler SR2, and the corresponding Marketplace Item that needs to be installed: Java 8 support for Eclipse Kepler SR2).
In my opinion you should udpate to the latest Eclipse Version.
With Luna SR2 (4.4.2) no additional patch is necessary.
Ensure the 1.8 JRE is available in your Workspace:
Windows > Preferences: Java > Installed JREs
If this is not the case you can add a new JRE with the add button.
Ensure that JRE System Library
== JavaSE-1.8
for your Project
In the Package Explorer, you should see the Java version:
If this is not correct you should open the context menu the JRE System Library
item and select the Properties
menu entry.
In your project you have a .classpath
file (Use the Navigator View
if you do not see the file), that should looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Rebuild your project
Project Menu > Clean...
Select your project from the list or "Clean all projects" and "Start a build immediately"
See also:
- Explaination from @mkrakhin in his answer: The type java.lang.CharSequence cannot be resolved in package declaration
The type java.lang.CharSequence cannot be resolved
First of all, I did not manage to start an Indigo Eclipse (eclipse-SDK-3.7.2) with a Java 8 JVM, it fails at startup.
To check the Java Version your Eclipse is using, you can check:
Menu
> Help
> About Eclipse
. In the Dialog, click on the Installation Details
Button and switch to the Configuration
Tab. You will find a line:
java.version=1.7.0_45
If you want an Eclipse IDE that can be started with Java 8, you should switch to Luna.
Now the JVM you use to run Eclipse is not automatically the one used by your project.
You can install additional JVM in the preferences:Java
> Installed JREs
In this example 2 JVM are available: jre6 and jre8.
A related concept is “Execution Environment”. Each Java project of your workspace is configured to work with a specific Java Environment. I have described in this answer how to ensure that Java 8 is correctly set (Execution Environment in the prefrences and in the Java Version used by the project).
The available JVMs are mapped to the Execution Environment in the preference page:
Java
> Installed JREs
> Execution Environment
By the way, in this page, you see that Java-SE-1.8
is not supported by Eclipse Indigo.
If your requirement is to use Eclipse Indigo, in my opinion you should stick to Java 1.7 or smaller.
Error in yyy.jspf at line 7: The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files
This error is related to an incompatibility between the WebLogic 11g JSP compiler and JDK 1.8.
See other details and a workaround from my answer to a similar error related to the same incompatibility: java.util.Map$Entry cannot be resolved Error using Java 1.8.
Related Topics
Best Way to Implement View.Onclicklistener in Android
Java_Home Is Set to an Invalid Directory:
How to Call a Restful Web Service from Android
Convert Base64 String to Image in Java
How to Pass Values Between a Dialog and an Activity
How to Fetch Android Market Data When There Is No API
Recyclerview Not Call Oncreateviewholder
Requestlegacyexternalstorage Is Not Working in Android 11 - API 30
Writing Pcm Recorded Data into a .Wav File (Java Android)
Can't Get Okhttp's Response.Body.Tostring() to Return a String
Android Overlay a View Ontop of Everything