我正在用NetBeans上的JavaFX2制作一个文本编辑器应用程序。我的问题是:每当我尝试插入链接css的scene.getStylesheets().add(<classname>.class.getResource("<css file>.css").toExternalForm());行,并运行它时,它显示一个错误:“运行应用程序时出现异常”。
这个例外到底是什么?我试着删除这一行,然后应用程序运行得很流畅。就在五六个小时前,我插入了这行代码(使用正确的类和css文件),它可以很容易地使用css。但现在,我已经创建了另外3个项目来检查它,但应用程序显示相同的错误,并在删除此代码时被删除。我通过右键单击Source-packages图标> new > Cascading Style Sheets来创建Css。我为css文件填写了所有正确的类和位置,但仍会发生这种情况。我还尝试了Shift + F11 (清理并重建)。当我启动较旧的应用程序(使用css)时,它运行时没有错误。(顺便说一句,我使用Win8专业版x64,如果你需要的话)
输出面板在Executing com.javafx.main.Main from <location>\Qwerty.jar using platform C:\Program Files\Java\jdk1.7.0_17/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:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.javafx.main.Main.launchApp(Main.java:642)
at com.javafx.main.Main.main(Main.java:805)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at qwerty.Qwerty.start(Qwerty.java:36) (LINE 36 is where the reference to css is)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:215)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
... 1 more
Java Result: 1发布于 2013-04-20 00:20:50
这个问题在嵌套的excpetion中解释:
原因: java.lang.NullPointerException at qwerty.Qwerty.start(Qwerty.java:36) (第36行是对css的引用)
检查<classname>.class.getResource("<css file>.css")是否为空。也许您指定了错误的路径,或者css不在jar中?
https://stackoverflow.com/questions/16108225
复制相似问题