Eclipse 错误:无法解析 java.lang.CharSequence

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24727428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 14:30:33  来源:igfitidea点击:

Eclipse Error: java.lang.CharSequence cannot be resolved

javaeclipse

提问by felipeek

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

我在尝试在 Eclipse 中编译一个简单的代码时遇到错误。我正在使用 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.

Collections.sort(myList);在行中出错。

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!

我已经打开了 eclipse Build Path,删除了 JRE 系统库 [jre8] 并再次添加了它。但是没有用!我能做什么?谢谢!

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

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

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

无法解析 java.lang.CharSequence 类型。它是从所需的 .class 文件中间接引用的。

采纳答案by Jmini

Ensure that your Eclipse IDE supports Java 8:

确保您的 Eclipse IDE 支持 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).

第一个支持 Java 8 的 Eclipse 版本是带有附加补丁的 Eclipse Kepler SR2 (4.3.2)。(请参阅:在 Eclipse Kepler SR2 中安装 Java?8 支持,以及需要安装的相应市场项:Eclipse Kepler SR2 的 Java 8 支持)。

In my opinion you should udpate to the latest Eclipse Version.

在我看来,您应该更新到最新的 Eclipse 版本

With Luna SR2 (4.4.2) no additional patch is necessary.

Luna SR2 (4.4.2) 不需要额外的补丁。



Ensure the 1.8 JRE is available in your Workspace:

确保 1.8 JRE 在您的工作区中可用:

Windows > Preferences: Java > Installed JREs

Windows > 首选项:Java > 已安装的 JRE

Installed JREs

已安装的 JRE

If this is not the case you can add a new JRE with the add button.

如果不是这种情况,您可以使用添加按钮添加新的 JRE。



Ensure that JRE System Library== JavaSE-1.8for your Project

确保JRE System Library==JavaSE-1.8为您的项目

In the Package Explorer, you should see the Java version:

在 Package Explorer 中,您应该会看到 Java 版本:

Package Explorer

包浏览器

If this is not correct you should open the context menu the JRE System Libraryitem and select the Propertiesmenu entry.

如果这不正确,您应该打开上下文菜单JRE System Library项并选择Properties菜单项。

JRE System Library - Properties

JRE 系统库 - 属性

In your project you have a .classpathfile (Use the Navigator Viewif you do not see the file), that should looks like this:

在您的项目中,您有一个.classpath文件(Navigator View如果您没有看到该文件,请使用 ),它应该如下所示:

<?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:

也可以看看:

回答by u9078752

This is because the BytecodeParser class in soot.JastAddJ doesn't support higher version of java class file format.The CONSTANT_MethodHandle,CONSTANT_MethodType and CONSTANT_InvokeDynamic of constant pool type missed.Below is my solution to fix the question:

这是因为 soot.JastAddJ 中的 BytecodeParser 类不支持更高版本的 java 类文件格式。常量池类型的 CONSTANT_MethodHandle、CONSTANT_MethodType 和 CONSTANT_InvokeDynamic 缺失。以下是我解决问题的解决方案:

(1) add the type int soot.JastAddJ.BytecodeParser:

(1) 添加类型 int soot.JastAddJ.BytecodeParser:

private static final int CONSTANT_MethodHandle=15;
private static final int CONSTANT_MethodType=16;
private static final int CONSTANT_InvokeDynamic=18;

(2) add 3 classes to support the parse:

(2) 添加3个类来支持解析:

in the method parseEntryof soot.JastAddJ.BytecodeParser,add

parseEntrysoot.JastAddJ.BytecodeParser的方法中,添加

CONSTANT_MethodHandle_Info, CONSTANT_MethodType_Info, CONSTANT_InvokeDynamic_Info

CONSTANT_MethodHandle_Info、CONSTANT_MethodType_Info、CONSTANT_InvokeDynamic_Info

in the switch case block.

在开关盒块中。

Now,soot can run successfully.

现在,soot 可以成功运行了。