我的程序之前工作得很好,并且我将场景构建器从JavaFx场景构建器2.0更改为胶子场景构建器10以添加一些CSS样式.我添加了样式,程序显示错误,例如 警告:使用版本10.0.1的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.(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); } }
我的Controller类是
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"); } } }
我的FXML文件是
堆栈跟踪将此显示为错误的行
Parent root = FXMLLoader.load(getClass().getResource("../Interface/sample.fxml"));
我一直在浪费超过3个小时来寻找答案.所以请帮助我.
fontawesome版本:
这个错误:
Caused by: java.lang.NoClassDefFoundError: com/sun/javafx/css/parser/CSSParser at de.jensd.fx.glyphs.GlyphIcon.(GlyphIcon.java:48) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
表示您的某个依赖项(de.jensd.fx.glyphs.GlyphIcon
)正在尝试访问com.sun.javafx.css.parser.CSSParser
JDK 9/10中的非现有类().
在Java 9发行版中,许多private(com.sun.javafx.*
)的JavaFX类被移动到公共API(在本例中javafx.css.parser.CSSParser
).
如果在Java 9或10上运行,则必须使用至少与Java 9兼容的第三方依赖项.
从您的依赖项列表:
ControlsFX
8.40.11与Java/JavaFX 8兼容.您需要使用ControlsFX 9.0.0
您可以从Maven Central 下载jar,或添加maven/gradle坐标:
org.controlsfx controlsfx 9.0.0
要么:
compile 'org.controlsfx:controlsfx:9.0.0'
FontAwesomeFX
FontAwesomeFX 8.15也与Java/JavaFX 8兼容,因此您需要使用9个版本:
罐子: 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运行它的新版本创建的.它可以被忽略.