Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error resolving FXML file #68

Open
aalmiray opened this issue Dec 15, 2020 · 2 comments
Open

Error resolving FXML file #68

aalmiray opened this issue Dec 15, 2020 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@aalmiray
Copy link
Contributor

As a follow up t #67, there seems to be a problem when resolving types consumed in an FXML file. The following code fails

App.java

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

import java.net.URL;

public class App extends Application {
    @Override
    public void start(Stage stage) throws Exception {
        URL location = getClass().getResource("app.fxml");
        FXMLLoader fxmlLoader = new FXMLLoader(location);
        HBox hbox = fxmlLoader.load();

        Scene scene = new Scene(hbox);
        stage.setScene(scene);
        stage.setTitle("App");
        stage.show();
    }

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

module-info.java

module app {
    exports app;
    requires javafx.base;
    requires javafx.graphics;
    requires javafx.controls;
    requires javafx.fxml;
}

layers.toml

[layers.javafx]
    modules = [
        "org.openjfx:javafx-base:jar:{{os.detected.jfxname}}:{{javafx_version}}",
        "org.openjfx:javafx-controls:jar:{{os.detected.jfxname}}:{{javafx_version}}",
        "org.openjfx:javafx-graphics:jar:{{os.detected.jfxname}}:{{javafx_version}}",
        "org.openjfx:javafx-fxml:jar:{{os.detected.jfxname}}:{{javafx_version}}"]
[layers.core]
    modules = [
        "org.kordamp.ikonli:app:{{project_version}}"]
    parents = ["javafx"]
[main]
  module = "app"
  class = "app.App"

versions.properties

project_version = 12.0.1-SNAPSHOT
javafx_version = 11

The error I get is

Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Couldn't run module main class
	at org.moditect.layrry.internal.LayersImpl.run(LayersImpl.java:139)
	at org.moditect.layrry.Layrry.launch(Layrry.java:56)
	at org.moditect.layrry.Layrry.run(Layrry.java:50)
	at org.moditect.layrry.launcher.LayrryLauncher.launch(LayrryLauncher.java:53)
	at org.moditect.layrry.launcher.LayrryLauncher.main(LayrryLauncher.java:35)
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.moditect.layrry.internal.LayersImpl.run(LayersImpl.java:136)
	... 4 more
Caused by: java.lang.RuntimeException: Exception in Application start method
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
	at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: javafx.fxml.LoadException: 
file:///Users/aalmiray/.m2/repository/org/kordamp/ikonli/app/12.0.1-SNAPSHOT/app-12.0.1-SNAPSHOT.jar!/app/app.fxml

	at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625)
	at javafx.fxml/javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2863)
	at javafx.fxml/javafx.fxml.FXMLLoader.processImport(FXMLLoader.java:2707)
	at javafx.fxml/javafx.fxml.FXMLLoader.processProcessingInstruction(FXMLLoader.java:2676)
	at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2542)
	at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
	at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2435)
	at [email protected]/app.App.start(App.java:33)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
	at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
Caused by: java.lang.ClassNotFoundException: javafx.geometry.Insets
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	at javafx.fxml/javafx.fxml.FXMLLoader.loadTypeForPackage(FXMLLoader.java:2931)
	at javafx.fxml/javafx.fxml.FXMLLoader.loadType(FXMLLoader.java:2920)
	at javafx.fxml/javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2861)

The javafx.geometry.Insets class is provided by the javafx.graphics module which is set as a requirement on the app module.

@aalmiray
Copy link
Contributor Author

It's worth mentioning that marking the module as open did not make a difference.

@aalmiray
Copy link
Contributor Author

As commented at #67 (comment) by @p-zalejko, the fix is to set an explicit classloader on the FXMLLoder instance. There's nothing to be done from Layrry's side other than documenting this use case.

@aalmiray aalmiray added the documentation Improvements or additions to documentation label Jan 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant