我正在使用 JavaFX 开发一个多平台应用程序,我正在使用 Win7 和 Netbeans 7.2.1 以及 JavaFX 2.2 和 Java 1.7u21(以前使用 1.7u9 并且工作得很好)。正如我所说,Win7 运行得很好我的应用程序。当我尝试在 Ubuntu 12.04 上运行它时,它根本无法加载我的 CSS 样式。每个 fxml 文件都添加了其控件的样式表类。然后每个控件都添加了它的样式。例如:在一个空白按钮上,我正在应用这种样式:
按钮样式.css:
.button {
-fx-text-fill: white;
-fx-alignment: CENTER;
-fx-border-radius: 5;
-fx-font-size: 13pt;
-fx-font-family: "Verdana";
-fx-font-weight: bold;
-fx-background-color: linear-gradient(#328BDB 0%, #207BCF 25%, #1973C9 75%, #0A65BF 100%);
}
.button:hover {
-fx-background-color: linear-gradient(#2C8AE7 0%, #0C6AC7 25%, #0A58A5 75%, #093B6D 100%);
}
.button:pressed {
-fx-background-color: linear-gradient(#328BDB 0%, #207BCF 25%, #1973C9 75%, #0A65BF 100%);
}
在 Win7 上工作正常,但它在 Ubuntu 上生成以下异常:
java.lang.ClassNotFoundException: AUTHOR
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.ArrayIndexOutOfBoundsException: 512
at com.sun.javafx.css.StyleConverter.readBinary(StyleConverter.java:99)
at com.sun.javafx.css.ParsedValue.readBinary(ParsedValue.java:600)
at com.sun.javafx.css.Declaration.readBinary(Declaration.java:142)
at com.sun.javafx.css.Rule.readBinary(Rule.java:189)
at com.sun.javafx.css.Stylesheet.readBinary(Stylesheet.java:185)
at com.sun.javafx.css.Stylesheet.loadBinary(Stylesheet.java:215)
at com.sun.javafx.css.StyleManager.loadStylesheetUnPrivileged(StyleManager.java:572)
at com.sun.javafx.css.StyleManager.loadStylesheet(StyleManager.java:411)
at com.sun.javafx.css.StyleManager.access$1900(StyleManager.java:72)
at com.sun.javafx.css.StyleManager$StylesheetContainer.gatherParentStylesheets(StyleManager.java:1140)
at com.sun.javafx.css.StyleManager$StylesheetContainer.getStyleHelper(StyleManager.java:1225)
at com.sun.javafx.css.StyleManager$StylesheetContainer.access$1300(StyleManager.java:1031)
at com.sun.javafx.css.StyleManager.getStyleHelper(StyleManager.java:968)
at javafx.scene.Node.impl_createStyleHelper(Node.java:7433)
at javafx.scene.Node.impl_processCSS(Node.java:7403)
at javafx.scene.Parent.impl_processCSS(Parent.java:1146)
at javafx.scene.Parent.impl_processCSS(Parent.java:1153)
at javafx.scene.Parent.impl_processCSS(Parent.java:1153)
at javafx.scene.Node.processCSS(Node.java:7383)
at javafx.scene.Scene.doCSSPass(Scene.java:443)
at javafx.scene.Scene.preferredSize(Scene.java:1445)
at javafx.scene.Scene.impl_preferredSize(Scene.java:1512)
at javafx.stage.Window$10.invalidated(Window.java:719)
at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:127)
at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:161)
at javafx.stage.Window.setShowing(Window.java:782)
at javafx.stage.Window.show(Window.java:797)
at javafx.stage.Stage.show(Stage.java:229)
at com.test.MainInterface.start(MainInterface.java:62)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:206)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:173)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication$3$1.run(GtkApplication.java:82)
... 1 more
删除buttonStyle.css并添加comboStyle.css,抛出以下异常:
组合样式.css:
.combo-box {
-fx-font: 13pt "Verdana";
-fx-alignment: baseline-left;
-fx-background-color: linear-gradient(#328BDB 0%, #207BCF 25%, #1973C9 75%, #0A65BF 100%);
}
.combo-box .text {
-fx-fill: white;
}
.combo-box .arrow-button {
-fx-background-color: linear-gradient(#328BDB 0%, #207BCF 25%, #1973C9 75%, #0A65BF 100%);
}
.combo-box .arrow {
-fx-background-color: white;
}
例外:
java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:267)
at com.sun.javafx.css.CompoundSelector.readBinary(CompoundSelector.java:351)
at com.sun.javafx.css.Selector.readBinary(Selector.java:113)
at com.sun.javafx.css.CompoundSelector.readBinary(CompoundSelector.java:344)
at com.sun.javafx.css.Selector.readBinary(Selector.java:113)
at com.sun.javafx.css.Rule.readBinary(Rule.java:182)
at com.sun.javafx.css.Stylesheet.readBinary(Stylesheet.java:185)
at com.sun.javafx.css.Stylesheet.loadBinary(Stylesheet.java:215)
at com.sun.javafx.css.StyleManager.loadStylesheetUnPrivileged(StyleManager.java:572)
at com.sun.javafx.css.StyleManager.loadStylesheet(StyleManager.java:411)
at com.sun.javafx.css.StyleManager.access$1900(StyleManager.java:72)
at com.sun.javafx.css.StyleManager$StylesheetContainer.gatherParentStylesheets(StyleManager.java:1140)
at com.sun.javafx.css.StyleManager$StylesheetContainer.getStyleHelper(StyleManager.java:1225)
at com.sun.javafx.css.StyleManager$StylesheetContainer.access$1300(StyleManager.java:1031)
at com.sun.javafx.css.StyleManager.getStyleHelper(StyleManager.java:968)
at javafx.scene.Node.impl_createStyleHelper(Node.java:7433)
at javafx.scene.Node.impl_processCSS(Node.java:7403)
at javafx.scene.Parent.impl_processCSS(Parent.java:1146)
at javafx.scene.Parent.impl_processCSS(Parent.java:1153)
at javafx.scene.Parent.impl_processCSS(Parent.java:1153)
at javafx.scene.Node.processCSS(Node.java:7383)
at javafx.scene.Scene.doCSSPass(Scene.java:443)
at javafx.scene.Scene.preferredSize(Scene.java:1445)
at javafx.scene.Scene.impl_preferredSize(Scene.java:1512)
at javafx.stage.Window$10.invalidated(Window.java:719)
at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:127)
at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:161)
at javafx.stage.Window.setShowing(Window.java:782)
at javafx.stage.Window.show(Window.java:797)
at javafx.stage.Stage.show(Stage.java:229)
at com.test.MainInterface.start(MainInterface.java:62)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:206)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:173)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication$3$1.run(GtkApplication.java:82)
at java.lang.Thread.run(Thread.java:722)
知道为什么这些样式不能在 Linux 中加载吗?