14

I'm trying to run this practice script from the standard Oracle Java tutorials.

This seems to be a common error and I've used SO resources to make attempts to fix this. I've tried Cleaning the project, refreshing the project, switch workplace and switch back, removed and re-added the JRE7.

I don't know what else to do.

import java.util.List;
import java.util.function.Consumer; -----> cannot be resolved ERROR
import java.util.function.Function; -----> cannot be resolved ERROR
import java.util.Comparator;
import java.util.function.Predicate; -----> cannot be resolved ERROR
import java.lang.Iterable;
import java.time.chrono.IsoChronology; -----> cannot be resolved ERROR

public class LambdaExpressions_RosterTest {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

    }

    }
jmj
  • 237,923
  • 42
  • 401
  • 438
StacyM
  • 1,036
  • 5
  • 23
  • 41

8 Answers8

16

Per the java.util.function Javadoc,

Since:
      1.8

So upgrade to Java 8, or try to find an older version of the tutorial.

I'm new at this. How can you tell what you are running? I'm using Eclipse

To determine your current Java version in eclipse, go to

Help -> About Eclipse -> Installation Details (Button in
          lower Left) -> Configuration pane

Look for the line java.specification.version - on my machine that is

java.specification.version=1.8

Or the line java.runtime.version - on my machine that is

java.runtime.version=1.8.0_11-b12
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • In Eclipse, how can I tell what Java I'm running? – StacyM Aug 05 '14 at 01:06
  • I'm running, Eclipse with ADT. It's different from those steps. I'm digging at this now... – StacyM Aug 05 '14 at 01:10
  • 1
    Right click on project, then properties, then Java Compiler, and note the "Compiler compliance level". If you don't see 1.8 available, install it first, then add it to Eclipse, and then it'll be available to you. – Jan Nielsen Aug 05 '14 at 01:11
  • I run a plain Windows 32 bit machine. Any advice which 1.8 to install? http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html – StacyM Aug 05 '14 at 01:17
  • 1
    @StacyM Windows x86 - the Offline version can be used to save yourself a lot of time if you're installing on multiple machines, the Online version downloads the Java installation content dynamically during installation. – Elliott Frisch Aug 05 '14 at 01:25
  • Ok, installed 1.8. Any tips on "add it to Eclipse"? When I go to Window - Preferences - Java - Compiler - Compiler Compliance Level, it doesn't show as available. – StacyM Aug 05 '14 at 01:42
  • 1
    Figured it out! Window - Preferences - Java - Installed JREs - Add Standard VM - path to C: Program Files\Java\jre8. – StacyM Aug 05 '14 at 01:46
14

i solved this problem by trying following solution

Project > Properties > Java Build Path
Select Libraries tab
Select JRE System Library
Click Edit button
Choose an alternate JRE (jre1.8.0_20)
Click Finish button

SoftwareDev
  • 336
  • 2
  • 13
4

Lambda Expressions are newly added into Java 8. They are not available for JRE7. Try to upgrade your eclipse project's JRE to 8 (window -> preferences->java->compiler).

Tapan Pandya
  • 114
  • 2
1

For idea IntelliJ you need to go to Menu-> Project Structure -> Module here you will see Source tab, above this tab you can see language level. change it to more than 8.

-yash

Yash Jagdale
  • 1,446
  • 14
  • 17
1

I had something similar with Apache Camel: the following function was not working anymore

String headerKey = exchange.getIn().getHeader("headerKey",String.class);

because of the error-message:

The type java.util.function.Supplier cannot be resolved. It is indirectly referenced from required .class files

To solve the issue I change the casting and it worked afterwards:

String headerKey = (String) exchange.getIn().getHeader("headerKey");

maybe it helps you or somebody else.

One other point to mention here would be the Apache Camel version itself as stated on the official page linked here.

IVIike
  • 87
  • 8
0

same problem is coming to me,I make a changes in eclipse.ini file and did -Dosgi.requiredJavaVersion=1.8 instead of -Dosgi.requiredJavaVersion=1.6 and my problem has been resolved.

0

Ran into this problem when the version I was using in the below properties was <1.8. Updating my POM to a version >1.8 resolved my issue.

<properties>
     <maven.compiler.source>1.9</maven.compiler.source>
     <maven.compiler.target>1.9</maven.compiler.target>
</properties>
shivakumar
  • 61
  • 1
  • 1
  • 5
0

I ran into this while trying to use Java 9 with Eclipse Oxygen. Eclipse claimed that I was using less than Java 1.8 and asked if I wanted to use 1.8. Saying yes solved the problem, but led to this error message later on.

I went in to Window => Preferences => Java => Compiler and saw that this had been changed to 1.8, so I changed it back to 9 and everything seems to be working now.

TylerH
  • 20,799
  • 66
  • 75
  • 101
cowang
  • 169
  • 1
  • 1
  • 12