0

I was following a tutorial for Java and when I tried to follow the code I received this error

Access restriction: The method 'ObservableList<Node>.addAll(Node[])' is not API (restriction on required library 'C:\Program Files\Java\jre1.8.0_131\lib\ext\jfxrt.jar')

on this line

layout1.getChildren().addAll(label1, button1);

I edited the access rules and it still won't work, even though the other liberties are defined and work. Does anyone have any ideas how to fix this.

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class test extends Application {

    Stage window;
    Scene scene1, scene2;

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        window = primaryStage;

        //Button 1
        Label label1 = new Label("Welcome to the first scene!");
        Button button1 = new Button("Go to scene 2");
        button1.setOnAction(e -> window.setScene(scene2));

        //Layout 1 - children laid out in vertical column
        VBox layout1 = new VBox(20);
        layout1.getChildren().addAll(label1, button1);
        scene1 = new Scene(layout1, 200, 200);


        //Button 2
        Button button2 = new Button("This sucks, go back to scene 1");
        button2.setOnAction(e -> window.setScene(scene1));

        //Layout 2
        StackPane layout2 = new StackPane();
        layout2.getChildren().add(button2);
        scene2 = new Scene(layout2, 600, 300);

        //Display scene 1 at first
        window.setScene(scene1);
        window.setTitle("Title Here");
        window.show();
    }


    }

}
Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
Erik
  • 15
  • 1
  • Your code ran fine for me once I removed the last `}`. – SedJ601 Mar 15 '18 at 18:27
  • Are you using eclipse? This answer references some project settings you might need to change. https://stackoverflow.com/questions/25222811/access-restriction-the-type-application-is-not-api-restriction-on-required-l – Nicholas Hirras Mar 15 '18 at 18:29
  • Here's a [JavaFX-specific version](https://stackoverflow.com/questions/22812488/using-javafx-in-jre-8/32062263) of the question @NicholasSmith linked. – James_D Mar 15 '18 at 19:37

0 Answers0