Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Spring Basics Modeling, Storing, and Presenting Data Feeding Data to Our Thymeleaf Templates

Paul Yorde
Paul Yorde
10,497 Points

java.time package not recognized or does not exist. Shouldn't this be a part of the standard JDK?

I am getting an error complaining that the java.time package does not exist. I have imported at the top of the Gif.java, GifController filess as so:

    import java.time.LocalDate;

It is however being recognized when I Use LocalDate to declare the variable. But then it says can't recognize symbol to the variable it allowed me to make.

3 Answers

Seth Kroger
Seth Kroger
56,413 Points

LocalDate is an addition to the JDK in Java 8. If the installed JDK version is lower than 8 or the language level of the project is lower, you won't be able to use it. (check the sourceCompatibility setting in the build.gradle file.)

Paul Yorde
Paul Yorde
10,497 Points

So, can I change the sourceCompatability setting. It is 1.5. and my path to the JDK says 1.8. My intelij is v15 and my mac is running Java 8.

Seth Kroger
Seth Kroger
56,413 Points

Yes, changing that should fix thing if everything else is ok.

Paul Yorde
Paul Yorde
10,497 Points

sourceCompatibility 1.8 doesn't work with language level 1.8. Can I bring java.time package into my project? How do I do that? Does that have to with add Jar to the project?

Jeremiah Shore
Jeremiah Shore
31,168 Points

Paul Yorde once you add the the following to your build.gradle file...

sourceCompatibility = 1.8

...make sure you manually refresh the Gradle project. You should only need the import statement as you have it...

import java.time.LocalDate;

...and that should be it. You can also check the language level is correct in your project by navigating to File > Project Structure > Project Settings > Project > Project language level. I believe Gradle supplies sourceCompatibility = 1.5 as a default, hence the suggestion to refresh once you have changed the value, as doing so should set the correct language level.

I tried doing that and I got a pop-up showing "unindexed remote maven repositories found" in IntelliJ. I tied updating the Repositories and I ended up with "Java.lang.RunTimeException: java.io.IOException: Transfer for nexus-maven-repository-index.gz failed" error

Can somebody help me on this.

Edward Poon
Edward Poon
9,313 Points

The following fixed the issue for me so hopefully it will help you. Go to the toolbar and click on IntellijIDEA -> Preferences -> (On the Left Hand side) Build, Execution, Deployment -> Gradle and in the Gradle JVM specify it was 1.8. Mine was specified as 1.7 so changing it to 1.8 fixed it for me.