Eclipse错误:java.lang.CharSequence无法解析 [英] Eclipse Error: java.lang.CharSequence cannot be resolved

查看:1586
本文介绍了Eclipse错误:java.lang.CharSequence无法解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Eclipse中编译一个简单的代码时遇到错误。我正在使用jre8。



例如,当我尝试编译这段代码:

  import java.util.ArrayList; 
import java.util.Collections;
import java.util.List;

public class MyProject {
public static void main(String args [])
{
列表< String> myList = new ArrayList< String>();

myList.add(test);
myList.add(test2);

Collections.sort(myList);
}
}

我在 Collections.sort(myList); 行。



错误是:

 线程main中的异常java.lang.Error:未解决的编译问题:
无法解析类型java.lang.CharSequence。它是间接引用的.class文件

在project.Principal.main(Principal.java:14)

我已经打开eclipse Build Path,删除了JRE System Library [jre8]并再次添加。但没有工作!我能做什么?谢谢!



PS .:在 Collections.sort(myList); 行eclipse显示此错误: p>

无法解析java.lang.CharSequence类型。

解决方案

确保您的Eclipse IDE支持Java 8: h1>

支持Java 8的第一个Eclipse版本是Eclipse Kepler SR2(4.3.2),还有一个补丁。 (见:

I'm getting a error trying to compile a simple code in Eclipse. I'm using jre8.

For example, when I try to compile this code:

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MyProject {
    public static void main (String args[])
    {
        List<String> myList = new ArrayList<String>();

        myList.add("test");
        myList.add("test2");

        Collections.sort(myList);
    }
}

I get a error in the Collections.sort(myList); line.

The error is:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files

    at project.Principal.main(Principal.java:14)

I have already opened eclipse Build Path, removed JRE System Library [jre8] and added it again. But didn't work! What can I do? Thanks!

PS.: In the Collections.sort(myList); line eclipse shows this error:

The type java.lang.CharSequence cannot be resolved. It is inderectly referenced from required .class files.

解决方案

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:

这篇关于Eclipse错误:java.lang.CharSequence无法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆