我的程序以前工作得很好,我将我的场景构建器从JavaFx场景构建器2.0改为gluon场景构建器10,以添加一些CSS样式。我添加了样式,程序显示了如下错误:警告:由版本9.0.4的JavaFX运行时用版本10.0.1的JavaFX API加载FXML文档,然后我将JDK更新到版本10.0.2,但它显示了如下错误。
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:473)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:372)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:941)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:973)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:198)
at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.lang.NoClassDefFoundError: com/sun/javafx/css/parser/CSSParser
at de.jensd.fx.glyphs.GlyphIcon.<clinit>(GlyphIcon.java:48)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
at java.base/java.lang.Class.newInstance(Class.java:560)
at javafx.fxml/javafx.fxml.FXMLLoader$InstanceDeclarationElement.constructValue(FXMLLoader.java:1019)
at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:754)
at javafx.fxml/javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2722)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3253)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3210)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3179)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3152)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3129)
at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3122)
at sample.Main.start(Main.java:17)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:175)
... 1 more
Caused by: java.lang.ClassNotFoundException: com.sun.javafx.css.parser.CSSParser
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
... 27 more
Exception running application sample.Main
我的主要课程是
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("../Interface/sample.fxml"));
primaryStage.setTitle("JFS");
primaryStage.setScene(new Scene(root, 600, 400));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
我的控制器类是
public class Controller {
public TextField newsletterEmail;
public JFXButton regButton;
public JFXTextField loginUserName;
public JFXPasswordField loginPassword;
public JFXButton loginButton;
Connectivity connection = new Connectivity();
Connection connec = connection.getConnection();
SceneSwitcher sceneSwitcher = new SceneSwitcher();
ViewMyAccount viewMyAccount = new ViewMyAccount();
loginValidation validateLogin = new loginValidation();
public void loginButtonClicked(ActionEvent actionEvent) {
System.out.println(loginUserName.getText());
/*viewMyAccount.setMailLabel(loginUserName.getText());
System.out.println(viewMyAccount.getMailLabel());*/
boolean validateCustomer = validateLogin.CusLoginValidate(loginUserName.getText(),loginPassword.getText(),connec);
boolean validateStaff = validateLogin.StaffLoginValidate(loginUserName.getText(),loginPassword.getText(),connec);
boolean validateOwner = validateLogin.OwnerLoginValidate(loginUserName.getText(),loginPassword.getText(),connec);
if(loginUserName.getText().equals("") || loginPassword.getText().equals("")){
AlertBox.displayAlertBox("ERROR!","Both fields can't be empty!");
}else{
if(validateCustomer){
sceneSwitcher.switchScene(loginButton,"customerView.fxml","Customer");
}else if(validateStaff){
sceneSwitcher.switchScene(loginButton,"staffView.fxml","Customer");
}else if(validateOwner){
sceneSwitcher.switchScene(loginButton,"ownerView.fxml","Customer");
}else{
AlertBox.displayAlertBox("ERROR!","Invalid Username or Password! ");
}
}
}
public void registerButtonClicked(ActionEvent actionEvent) {
sceneSwitcher.switchScene(regButton,"register.fxml","Register");
}
NewsletterValidation validateEmail = new NewsletterValidation();
public void newsletterButtonClicked(ActionEvent actionEvent) throws SQLException {
boolean isNewsletterEmailEmpty = validateEmail.invalidError(newsletterEmail);
boolean isValid = validateEmail.isValidEmailAddress(newsletterEmail);
boolean isEmailExist = validateEmail.checkEmailExists(newsletterEmail.getText(),connec);
if(isNewsletterEmailEmpty && isValid && isEmailExist){
PreparedStatement pstmt = null;
String sql = "INSERT INTO `nwemails` (`email`)\n" +
"VALUES (?);";
try {
pstmt = connec.prepareStatement(sql);
pstmt.setString(1,newsletterEmail.getText());
int i = pstmt.executeUpdate();
System.out.println("newsletter email update status = " + i);
AlertBox.displayAlertBox("Alert!","You have successfully signed up for the news letter");
} catch (SQLException e) {
System.err.println(e);
}finally {
pstmt.close();
}
}else{
System.out.println("Validation failed");
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXPasswordField?>
<?import com.jfoenix.controls.JFXTextField?>
<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" stylesheets="@../CSS/dracula.css" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<children>
<Label layoutX="227.0" layoutY="259.0" prefHeight="17.0" prefWidth="127.0" text="Don't have an account?" />
<Label layoutX="207.0" prefHeight="74.0" prefWidth="182.0" text="JFS" AnchorPane.leftAnchor="207.0" AnchorPane.rightAnchor="211.0" AnchorPane.topAnchor="0.0">
<font>
<Font name="Matura MT Script Capitals" size="53.0" />
</font>
</Label>
<Label layoutX="241.0" layoutY="98.0" prefHeight="17.0" prefWidth="118.0" text="Jeff's Fishing Shack" textAlignment="CENTER">
<font>
<Font name="Marlett" size="13.0" />
</font>
</Label>
<Button layoutX="186.0" layoutY="370.0" mnemonicParsing="false" onAction="#newsletterButtonClicked" prefHeight="25.0" prefWidth="210.0" text="Send me Updates" />
<Label layoutX="111.0" layoutY="316.0" prefHeight="17.0" prefWidth="378.0" text="Or sign up for The free newsletter covering the top industry headlines" />
<TextField fx:id="newsletterEmail" layoutX="195.0" layoutY="339.0" prefHeight="25.0" prefWidth="191.0" promptText="Email" />
<JFXTextField fx:id="loginUserName" layoutX="203.0" layoutY="136.0" prefHeight="25.0" prefWidth="191.0" promptText="Username (email)" />
<JFXPasswordField fx:id="loginPassword" layoutX="203.0" layoutY="185.0" prefHeight="25.0" prefWidth="191.0" promptText="Password" />
<FontAwesomeIconView glyphName="USER" layoutX="171.0" layoutY="161.0" size="25.0" wrappingWidth="15.0" />
<FontAwesomeIconView glyphName="KEY" layoutX="170.0" layoutY="208.0" size="25.0" wrappingWidth="15.0" />
<JFXButton fx:id="loginButton" layoutX="265.0" layoutY="225.0" onAction="#loginButtonClicked" text="LOGIN" />
<JFXButton fx:id="regButton" layoutX="257.0" layoutY="284.0" onAction="#registerButtonClicked" text="REGISTER" />
</children>
</AnchorPane>
Parent root = FXMLLoader.load(getClass().getResource("../Interface/sample.fxml"));
fontawesome版本:
此错误:
Caused by: java.lang.NoClassDefFoundError: com/sun/javafx/css/parser/CSSParser
at de.jensd.fx.glyphs.GlyphIcon.<clinit>(GlyphIcon.java:48)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
表示您的一个依赖项(de.jensd.fx.glyphs.glyphicon
)正在尝试访问JDK 9/10中不存在的类(com.sun.javafx.css.parser.cssparser
)。
在Java9版本中,许多私有的JavaFX类(com.sun.JavaFX.*
)被移到了公共API(在本例中为JavaFX.css.parser.cssparser
)。
如果在Java9或10上运行,则必须使用至少与Java9兼容的第三方依赖项。
从依赖项列表中:
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>9.0.0</version>
</dependency>
compile 'org.controlsfx:controlsfx:9.0.0'
JAR:FontaweSomeFX-Commons,FontaweSomeFX-Controls
或依赖项:
compile 'de.jensd:fontawesomefx-commons:9.1.2'
compile 'de.jensd:fontawesomefx-controls:9.1.2'
其他:
compile 'de.jensd:fontawesomefx-emojione:3.1.1-9.1.2'
compile 'de.jensd:fontawesomefx-fontawesome:4.7.0-9.1.2'
compile 'de.jensd:fontawesomefx-icons525:4.2.0-9.1.2'
compile 'de.jensd:fontawesomefx-materialdesignfont:2.0.26-9.1.2'
compile 'de.jensd:fontawesomefx-materialicons:2.2.0-9.1.2'
compile 'de.jensd:fontawesomefx-octicons:4.3.0-9.1.2'
compile 'de.jensd:fontawesomefx-weathericons:2.0.10-9.1.2'
最后,如注释中所示,警告只是表明您的FXML是用运行它的JDK的较新版本创建的。可以忽略不计。
第一个问题:由于将集成到容器(BorderPane)中,它本身不需要容器。但是SceneBuilder只提供了将布局创建为容器的选项? 第二个问题:我可以手动创建,然后手动修改以包括。然后,我可以使用SceneBuilder毫无问题地加载borderpane.fxml文件。但是,当我现在更改标签的文本并选择“保存”时,修改的不是,而是如下所示: 新标签文本应该写入,而不是写入。 我想为我的GUI的
}`我正在计划在同一舞台上使不同的部分成为自己的场景。如果有任何帮助,我将不胜感激。我正在使用NetBeans8.2。
请用简单的语言回答以上问题。如果可能的话,为我提供一些如何使用JavaFX的好教程。
我在javafx场景构建器中设计了一个用户界面,它在stackpane中有一个简单的按钮。我将控制器类命名为简单类。我已经保存了fxml作为simple.fxml.我在netbean中创建了一个控制器类,它只是在单击按钮时打印一些msg。 在NewFXBuilderJava中,我加载了simple。fxml。请在下面找到NewFXBuilder。java代码。 我的想法很简单。fxml,simpl
问题内容: 大家好,我正在构建一个JavaFX项目并正在使用JavaFX Scene Builder2。我想将控制器链接到我的fxml文件,但是我看不到在Scene Builder 2中将控制器添加到我的fxml文件的可能性。我想知道是否有人可以帮助我。谢谢。 问题答案: 我偶然在SceneBuilder 2中找到了控制器属性。关闭左侧的层次结构菜单时,将显示“控制器”菜单,可以在其中声明我的控制
我试图找到难以捉摸的JavaFX场景构建器,以便在IntelliJ中使用它。我在Windows操作系统上。 我已经安装了Java8SDK,并且运行良好。显然JavaFX现在包含在其中,但在Java文件夹的任何地方我都找不到场景构建器,它似乎在网上完全消失了。 有人能帮忙吗?我只是想写一个小的GUI程序,看来JavaFX是一个可行的方法(如果不是,那么请不要滥用我的这种想法!)