Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

java: package jdk.incubator.foreign is not visible error in Java 15

So I have downloaded JDK 15 - OpenJDK .

Running in Intelij the following code

import jdk.incubator.foreign.MemorySegment;  //The problem seems to occur here in this import

public class Application {

    public static void main(String[] args){

      MemorySegment m = MemorySegment.allocateNative(400L);

   }

 }

In inteliJ I have gone to File -> Project Structure -> Project SDK -> selected 15

In Application configurations (Intelij run project) I have declared JRE 15 (java version 15.0.2)

I receive the following error

C:Users
epositoriesjava15projectsrcmainuntitledsrcApplication.java:2:21
java: package jdk.incubator.foreign is not visible
(package jdk.incubator.foreign is declared in module jdk.incubator.foreign, which is not in the module graph)

Could someone please help me?

question from:https://stackoverflow.com/questions/65861700/java-package-jdk-incubator-foreign-is-not-visible-error-in-java-15

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Run with option --add-modules jdk.incubator.foreign

Alternatively, create a module-info.java file, e.g. like this:

module my.module.name.here {
    requires jdk.incubator.foreign;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...