Location is required in JavaFX with gradle

前端 未结 4 642
不思量自难忘°
不思量自难忘° 2020-12-31 17:23

I\'m getting

java.lang.NullPointerException: Location is required.

when I run my program after assembling using gradle with jav

相关标签:
4条回答
  • 2020-12-31 18:02

    Try replacing:

    javaRuntime = 'C:\\Program Files\\Java\\jdk1.7.0_45'
    

    with:

    javaRuntime = 'C:/Program Files/Java/jdk1.7.0_45'
    
    0 讨论(0)
  • 2020-12-31 18:16

    Actually, loading a resource with Gradle might be different from using your IDE resource system.

    It is better to use the ClassLoader :

    URL myFxmlURL = ClassLoader.getSystemResource("fxml_example.fxml");
    FXMLLoader loader = new FXMLLoader(sampleUrl);
    
    Parent root = loader.load(myFxmlURL);
    
    0 讨论(0)
  • 2020-12-31 18:19

    I'm really late to the party...but the accepted didn't work. I (randomly) added 'javafx.fxml' to the list of modules, like this

    javafx {
        version = "14"
        modules = [ 'javafx.controls', 'javafx.fxml']
    }
    

    ...and it solved the issue.

    0 讨论(0)
  • 2020-12-31 18:22

    Your FXML files are probably not packaged into your jar.

    Try adding this to your build.gradle file:

    sourceSets {
      main {
        resources {
            srcDirs = ["src/main/java"]
            includes = ["**/*.fxml"]
        }
      }
    }
    
    0 讨论(0)
提交回复
热议问题