As the title suggest, I just want to separate (organize) the files inside my project, before everything I've read this:
- How to seperate Javafx(non fxml) to a fxml and a controller? (Invocation target exception)
- Is there a way to modularize a JavaFX application?
- How to seperate logic from controller JavaFx
This is the most approached answer.
But it's no quite clear for me still tho, (perhaps it's about I don't understand grammar cuz english is not my native lang).
I tried to replicate the last one manually, but still can't figure how should I point to the fxml files.
Here is my structure:
The code for my main app:
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
/**
* Principal
* @author Adrian
*
*/
public class Login extends Application {
@Override
public void start(Stage primaryStage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("login.fxml"));
Scene scene = new Scene(root,300,200);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setTitle("Login");
primaryStage.setScene(scene);
primaryStage.show();
Image icono = new Image(getClass().getResourceAsStream("/SiLi/src/main/recursos/img/usuario.gif"));
primaryStage.getIcons().add(icono);
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
The error I get:
> java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at org.ajfmo.sili.core.Login.start(Login.java:19)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)