简体   繁体   中英

In Java on Eclipse IDE, I'm receiving an error on the package line (the first line in the class)

package packageName;
public class ClassName{
    public static void main(String[] args) {
        //code
    }

The error is on "package packageName;"and it says "The type java.lang.constant.ConstantDesc cannot be resolved. It is indirectly referenced from required.class files"

I don't think the code is relevant because I've seen this error in multiple classes.

I have no idea what it means, so any help would be greatly appreciated.

The missing class was introduced with Java 12. ( see https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/lang/constant/ConstantDesc.html )

So you must ensure to have a JDK 12 listed inside your JDK/JRE preferences as shown in next picture (the picture shows an old JDK8 is set as default...) .
显示已安装 JRE 的 Eclipse 首选项的图片

You have to press the Add button and follow the steps inside the shown wizard, select your JDK 12 installation directory and set to default.

After this your workspace will rebuild and the failures should disappear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM