Forum Stats

  • 3,827,642 Users
  • 2,260,802 Discussions
  • 7,897,323 Comments

Discussions

Why do I get these error msgs using javafx?

TranceShifter
TranceShifter Member Posts: 1
edited Jun 29, 2016 10:03PM in Java 8 Questions

               While using eclipse IDE and learning javafx8 I am getting errors right in the IDE.  The first few apps compiled (with errors) and executed but now I can't even get them to execute.

example error msg:

Access restriction: The method 'FlowPane.setAlignment(Pos)' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home/jre/lib/ext/jfxrt.jar')

My code:  (Yeah it's beginner code but I'm a student so any help is appreciated);

It's almost as if it can't connect with the libraries.  Almost every line of actual code is an error - minor but still an error and all the error messages are similar to the one above.  Any help is appreciated!!!  Thanks!!!

import javafx.application.*;

import javafx.scene.*;

import javafx.stage.*;

import javafx.scene.layout.*;

import javafx.scene.control.*;

import javafx.event.*;

import javafx.geometry.*;

public class JavaFXEventDemo extends Application {

  Label response;

  public static void main(String[] args) {

  //System.out.println("Launching JavaFX application.");

  launch(args);

  }

  public void start(Stage myStage) {

  System.out.println("Inside the start() method.");

  // give the stage a title

  //myStage.setTitle("Introducing Java Buttons and Events");

  FlowPane rootNode = new FlowPane(10,10);

  // center the controls in the scene

  //System.out.println("Here we are.");

  rootNode.setAlignment(Pos.CENTER);

  // create a scene

  Scene myScene = new Scene(rootNode, 300, 100);

  // set the scene on the stage

  myStage.setScene(myScene);

  // create a label

  Label myLabel = new Label("Click a button");

  // create two push buttons

  Button btnFirst = new Button("First");

  Button btnSecond = new Button("Second");

  // Handle the action events for the first button

  btnFirst.setOnAction(new EventHandler<ActionEvent>() {

  public void handle(ActionEvent ae) {

  response.setText("First button was pressed.");

  }

  });

  // Handle the action events for the second button

  btnFirst.setOnAction(new EventHandler<ActionEvent>() {

  public void handle(ActionEvent ae) {

  response.setText("Second button was pressed.");

  }

  });

  // add the label and buttons to the scene graph

  rootNode.getChildren().addAll(btnFirst, btnSecond, response);

  // show the stage and its scene

  myStage.show();

  }

Answers

  • Unknown
    edited Jun 29, 2016 10:03PM
                   While using eclipse IDE and learning javafx8 I am getting errors right in the IDE.  The first few apps compiled (with errors) and executed but now I can't even get them to execute.

    1. The IDE is a Java app and uses a Java SDK

    2. Your code is a Java app and uses a Java SDK

    3. The IDE can, and often does, use a DIFFERENT version of Java than your Java app

    Your problem is likely that the IDE is using an older version of Java than your code is using and doesn't understand things in the newer version of Java.

    Compile your code manually and see what errors, if any, you get. That removes the IDE and its version of Java from any interference.