-4

I'm trying to create a JavaFX program, and every time when i add any thing from the library of jfoenix I try to run my code I am getting an exception - I'm not entirely sure what it means though...

My code is:

public class home extends Application {

    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("home.fxml"));
        Scene scene = new Scene(root,1300,768);
        scene.getStylesheets().add(getClass().getResource("Style.css").toExternalForm());
        stage.setScene(scene);
        stage.show();

     }

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

My controller is:

public class HomeController implements Initializable {

    @FXML
    private JFXButton log;

    @FXML
    private JFXButton engr;

    @FXML
    private Pane login,eng;

    @FXML
    private void changeofpages(MouseEvent event) {
        if (event.getTarget()== log){
            login.setVisible(true);
            eng.setVisible(false);
        }else
            if (event.getTarget()== engr){
            eng.setVisible(true);
            login.setVisible(false);
        }
    }

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
    }    
}

1 Answers1

0

This question is frequently repeated in javaFx ,i mean this exception :

Exception in Application start method

Because you did not post your stacktrace any one can find your problem ,i suggest to be sure of the following things :

In your main application :

  1. Be sure that path of your fxml file is correct.
  2. Be sure that path of your css file is correct.

In your controller :

  1. Be sure of node fx:id is present in fxml and it is correct.
  2. Be sure of importing classes for events.

Some time you find the same class name but it different packages

I give you an example of MouseEvent it is present in awt package and javafx package

I tried to write your code with all the conditions ,it invokes an exception because it can found the Style.css (maybe this is the error) ,but after that every thing is well :

This is your main application : package stackoverflow;

import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

/**
 *
 * @author Xlint Xms
 */
public class home extends Application {

    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("home.fxml")); //Be sure of your path
        Scene scene = new Scene(root, 1300, 768);
         scene.getStylesheets().add(getClass().getResource("Style.css").toExternalForm());//Be sure of your Style.css file
        stage.setScene(scene);
        stage.show();

    }

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

And your controller :

public class HomeController implements Initializable {

    @FXML
    private JFXButton log;

    @FXML
    private JFXButton engr;

    @FXML
    private Pane login,eng;

    /*Be sure of MouseEvent class :It is in javafx package not awt package*/
    @FXML
    private void changeofpages(MouseEvent event) {
        if (event.getTarget() == log) {
            login.setVisible(true);
            eng.setVisible(false);
        } else if (event.getTarget() == engr) {
            eng.setVisible(true);
            login.setVisible(false);
        }
    }
    @Override
    public void initialize(URL location, ResourceBundle resources) {
    }

This code is worked for me ,i hope for you too.

  • I think my problem is here :/*Be sure of MouseEvent class :It is in javafx package not awt package*/ but how I can do that – ڜخص متميژ Dec 16 '17 at 09:02
  • my problem is show just when i add any thing from the library of _jfoenix_ (**JFXButton** for exemple) – ڜخص متميژ Dec 16 '17 at 09:17
  • when I run it : `Caused by: java.lang.UnsupportedClassVersionError: com/jfoenix/controls/JFXTextField has been compiled by a more recent version of the Java Runtime (class file version 53.0), this version of the Java Runtime only recognizes class file versions up to 52.0 at java.lang.ClassLoader.defineClass1(Native Method)` – ڜخص متميژ Dec 16 '17 at 10:54
  • Check this answer https://stackoverflow.com/questions/27139583/java-compilation-errors-unsupported-class-version – Menai Ala Eddine - Aladdin Dec 16 '17 at 13:12