0

I have installed Java SE Runtime Environment 8u192 https://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html on Windows 10, and made some setting changes in Eclipse:

Window -> preferences -> java -> Installed JREs = jre1.8.0_192,

to make it use the new java.

When running this code:

package test;
public class LocalDateExample {
    public static void main(String[] args) {
        System.out.println(System.getProperty("java.version"));
    }
}

I get the output:

1.8.0_192


If I edit the code to:

package test;
import java.time.LocalDate;
public class LocalDateExample {
    public static void main(String[] args) {
        System.out.println(System.getProperty("java.version"));
        LocalDate localDate = LocalDate.now();
        System.out.println(localDate);
    }
}

I get this error:

LocalDate cannot be resolved to a type


Edit:

I believe that my problems comes from the fact, that Eclipse is missing Java 1.8 execution environment.

I can not just select it, as suggested here: How do I add execution environment 1.8 to Eclipse Luna? as it is missing completely.

Installed JRE Execution environments

What can I do to add or select the environment? I am using Eclipse

Helios Service Release 2 Build id: 20110301-1815 with no updates available.

hpekristiansen
  • 1,030
  • 3
  • 17
  • 35
  • 2
    *and made some setting changes in Eclipse(I do no longer know which), to make it use the new java.* ... then I suggest that you do a bit of research, for example reading here: https://stackoverflow.com/questions/13635563/setting-jdk-in-eclipse ... and then you check what JDK is configured for your eclipse. Probably: not this version of Java8? In other words: probably you "broke" your eclipse setup somehow. We can't help with that. – GhostCat Nov 13 '18 at 11:19
  • This error is happening because the import is not there. You have to let the `import java.time.LocalDate;` in your code, otherwise it won't work. Don't forget to check if your project is being build (Ctrl + b). – jhenrique Nov 13 '18 at 11:20
  • @GhostCat: I spend hours researching this. And I made the correct settings, as my output shows. – hpekristiansen Nov 13 '18 at 11:22
  • @jhenrique: I know the import is not there - please read the question again. – hpekristiansen Nov 13 '18 at 11:23
  • I undestand, but eclipse can't remove your code. Maybe you should download eclipse again, or unzip a fresh new one and try again. It can't be deleting your code. It may broke a bigger project in the future and you realize it too late. – jhenrique Nov 13 '18 at 11:25
  • 1
    @jhenrique: Eclipse is not just an editor, and it most definitely can and do correct imports among other things. – hpekristiansen Nov 13 '18 at 11:28
  • Yes, but not the correct ones. And in this case, that IS the correct import. – jhenrique Nov 13 '18 at 11:29
  • @jhenrique: My question is obscurred by this auto organize import thing - I will make some edits. – hpekristiansen Nov 13 '18 at 11:32
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/183557/discussion-between-jhenrique-and-hpekristiansen). – jhenrique Nov 13 '18 at 11:44
  • Just as a note, changing the installed JRE does not change the Java the Eclipse itself is using when it is launched. It can affect the compilation if it a)it is the default and the project does not have an execution environment, or b)the specific execution environment is set to use the new JRE. – KevinO Nov 13 '18 at 11:53
  • Thanks for the clarification. But well: your question didn't tell us. To the contrary. You see, telling us that you "dont know what is going on with your configuration" is a big red warning light telling people that there might be issues with your question ... that is all I am saying here. – GhostCat Nov 13 '18 at 12:18
  • Does the question still accurately say what the problem is? If the import can not be found by Eclipse, can *you* find it? And what version of Eclipse is involved? – nitind Nov 13 '18 at 19:36
  • @nitind Yes the problem persists. I have installed three different java versions, including jdk. Nothing helps. It is like eclipse is using import from one version(old, where there is no LocalDate), and using another version(the new one) to run the code. Is that possible? I can not check the eclipse version before tomorrow. – hpekristiansen Nov 13 '18 at 20:05
  • Did you check that the Installed JREs preference page pointed only at valid ones, and that your project referred to one of those valid ones either directly or indirectly, as @GhostCat pointed to with https://stackoverflow.com/questions/13635563/setting-jdk-in-eclipse ? – nitind Nov 13 '18 at 20:10

0 Answers0