Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

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\repositories\java15project\src\main\untitled\src\Application.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?

like image 368
Panagiotis Bougioukos Avatar asked Jun 18 '26 21:06

Panagiotis Bougioukos


1 Answers

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;
}
like image 170
Andreas Avatar answered Jun 21 '26 11:06

Andreas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!