如何使用资源修复此Javafx和CSS问题

时间:2019-05-11 15:00:24

标签: java css

我正在尝试通过使用CSS来更改Java应用程序的背景,但是资源方面存在一些问题。

下面的代码段应显示造成错误的部分。

我检查了jpg图像所在的src文件:C:\ Users \ Alpha \ Documents \ NetBeansProjects \ Login \ src \ login

图像名称正确,并且文件夹在那里(登录文件夹,CSS文件和background.jpg)。

Login.java类:

    Scene scene = new Scene(grid, 300, 275);
        scene.getStylesheets().add 
    (Login.class.getResource("Login.css").toExternalForm());

css1.css文件:

.root {
 -fx-backgroun-image: url("background.jpg");
}

我的输出中的错误:

Executing C:\Users\Alpha\Documents\NetBeansProjects\Login\dist\run755941160\Login.jar using platform C:\Program Files\Java\jdk1.8.0_201\jre/bin/java
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)`at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)`
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
at login.Login.start(Login.java:79)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(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$147(WinApplication.java:177)
... 1 more
Exception running application login.Login
Java Result: 1

0 个答案:

没有答案