11

What do I need in order to solve this problem? How to change JRE Library in Eclipse Project?

import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.stream.Stream;
import java.util.stream.Collectors;

public class LabelGroup {
SortedSet<String> strSet1 = Stream.of("A", "B", "C", "D")
             .collect(Collectors.toUnmodifiableSet());
    
}

Eclipse shows at Stream.of:

References to interface static methods are allowed only at source level 1.8 or above

Tried to install new software from official site as suggested by wiki.

Response:

Could not find (the software).

About Eclipse: Eclipse IDE for Enterprise Java Developers Version: 2018-12 (4.10.0) Build id: 20181214-0600

Project Settings: java build path: JRE System Library [JavaSE - 1.7]

Natasha Kurian
  • 407
  • 5
  • 11
Optimight
  • 2,989
  • 6
  • 30
  • 48
  • Did you make sure that the Java language version for your project is Java10 or above? Java 10 API => `Collectors.toUnmodifiableSet` – Naman Feb 25 '19 at 04:49
  • @nullpointer My Project Settings: java build path: JRE System Library [JavaSE - 1.7] How do I change the Java Language Version? – Optimight Feb 25 '19 at 04:55
  • This might help https://stackoverflow.com/questions/12588537/how-to-change-jdk-version-for-an-eclipse-project – Naman Feb 25 '19 at 04:57
  • 2
    Your problem is that the exception says that a feature is only available in 1.8 or later and your settings show you are using 1.7. – Jason Feb 25 '19 at 04:58
  • Not much value in this Question. Please [search thoroughly](https://duckduckgo.com/?q=How+do+I+change+the+Java+Language+Version+in+Eclipse&t=osx&ia=web) before posting and do some troubleshooting. – Basil Bourque Feb 25 '19 at 05:39
  • Duplicate of: [*Changing Java Version From Within Eclipse*](https://stackoverflow.com/q/10424528/642706) – Basil Bourque Feb 25 '19 at 05:41
  • Possible duplicate of [Changing Java Version From Within Eclipse](https://stackoverflow.com/questions/10424528/changing-java-version-from-within-eclipse) – Anton Sorokin Feb 25 '19 at 06:19
  • I struggled for almost 5 hours to find a solution to my problem. Tried everything that was suggested in comments. Installed Java 11, changed Build path, changed execution environment ... almost every setting which can show Java 11. But the problem did not solve. Finally when I changed the Compiler Compliance Level to 11, then only the problem got solved. – Optimight Feb 26 '19 at 16:50

4 Answers4

23

If you're working on a maven project and you're not able to change the JRE Library in Eclipse, then you can add the following dependency to the pom.xml

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>
Natasha Kurian
  • 407
  • 5
  • 11
8

1)Press on your project with right click and choose "Properties" enter image description here

2)choose java build Path from the left side

enter image description here

3)Press on "JRE System Library[JavaSe-1.5]" and press on Edit button

  1. in the open window we will choose the right JRE ( I use 11) and press finish

enter image description here

5)press Apply and Apply and Close

enter image description here

The issue suppose disappear

Vladi
  • 1,662
  • 19
  • 30
5

You have JDK 7 installed instead of JDK 8. The Stream API appeared only in Java 8. You can download Java 8(JDK 8 or OpenJDK) from the official site and install it as a JDK in your project.


Click on the Add Library button. It brings your screen to point to the Java location.

Select Directory, button right besides JRE home and point to the installed folder location.

Anton Sorokin
  • 494
  • 6
  • 23
1

If you are sure you have Java >= 1.8 installed and is in use in your workspace, try confirming that you do not have 'Project Specific Settings' enabled for that particular project.

Obalolu
  • 21
  • 1
  • 6