Java Eclipse中LocalDate无法解析为一种类型。

huangapple go评论113阅读模式
英文:

Java Eclipse LocalDate cannot be resolved to a type?

问题

以下是翻译好的代码部分:

package com.journaldev.java8.time;

import java.time.LocalDate;
import java.time.Month;
import java.time.ZoneId;

public class calendartest {

    public static void main(String[] args) {
        // 当前日期
        LocalDate today = LocalDate.now();
        System.out.println("当前日期=" + today);
    }
}

你确定你的 Java 版本是8,因为我通过命令行检查了一下,这是结果:

Java Eclipse中LocalDate无法解析为一种类型。

但不幸的是,当我运行我的代码时,结果是:

Exception in thread "main" java.lang.Error: 无法解析的编译问题
	LocalDate 无法解析为一种类型
	LocalDate 无法解析

你能否给我一些建议?非常感谢!

英文:

I am working with Java and trying to write a very simple test code like this to test LocalDate

package com.journaldev.java8.time;

import java.time.LocalDate;
import java.time.Month;
import java.time.ZoneId;

public class calendartest {

    public static void main(String[] args) {
        // Current Date
        LocalDate today = LocalDate.now();
        System.out.println("Current Date=" + today);
    }
}

I am sure that my java version is 8 because I checked by cmd and here is the result
Java Eclipse中LocalDate无法解析为一种类型。

But unfortunately, when I ran my code, the result is

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
	LocalDate cannot be resolved to a type
	LocalDate cannot be resolved

Could you please give me some comments ? Thank you very much!

答案1

得分: 1

我无法在您上传的图像上看到那个,但请确保源代码文件放在src/default包下。不应放在项目的根目录下。

要更改项目的Java版本,您可以按照此链接上的说明进行操作:https://www.baeldung.com/eclipse-change-java-version。

顺便说一下,我看到您已经选中了**“使用默认编译设置”**复选框,这就是您的更改未生效的原因。取消该选项,然后再试一次。

英文:

I can't see that on the image you uploaded, but be sure that source code file goes under src/default package. It should not be in the project's root directory.

To change the Java Version of project you can follow instructions given on this link : https://www.baeldung.com/eclipse-change-java-version.

By the way, I see that you checked "Use default compilance setting" checkbox, that is why your change is not applied. Uncheck that option and try again.

答案2

得分: 1

谢谢大家的评论。在经过4个小时后,我对自己的问题有了答案。最终我发现,我使用的是 Eclipse Helios 2010,所以我无法从 Jdk 1.7 升级到 Jdk 1.8。当我将 Eclipse Helios 更改为 Eclipse Luna 时,我所有的问题都解决了。顺便说一句,感谢大家的评论,祝你们一切顺利。

英文:

Thanks all for your comments. Here is my answer for my problem after 4 hours, finally I found that, I used Eclipse Helios 2010, so that I can not upgrade from Jdk 1.7 to Jdk 1.8. When I changed FROM Eclipse Helios to Eclipse Luna, ALL my problems have been gone. By the way thanks for your comments and wish you all the best.

huangapple
  • 本文由 发表于 2020年8月20日 17:10:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/63501877.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定