我正在创建一个简单的JavaFX应用程序,它抛出InvocationTargetException
。
package UI;
import java.io.IOException;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class MainFX extends Application {
private Stage stage;
private BorderPane borderPane;
@Override
public void start(Stage stage) throws IOException {
this.stage = stage;
this.stage.setTitle("App");
showMainView();
}
private void showMainView() throws IOException
{
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainFX.class.getResource("login.fxml"));
borderPane = loader.load();
Scene scene = new Scene(borderPane);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args)
{
launch(args);
}
}
login.fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXPasswordField?>
<?import com.jfoenix.controls.JFXSpinner?>
<?import com.jfoenix.controls.JFXTextField?>
<?import javafx.scene.effect.Light.Distant?>
<?import javafx.scene.effect.Lighting?>
<?import javafx.scene.effect.Shadow?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="480.0" prefWidth="640.0" style="-fx-background-color: #222629;" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="LoginController">
<center>
<GridPane BorderPane.alignment="CENTER">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="208.0" minWidth="10.0" prefWidth="166.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="414.0" minWidth="10.0" prefWidth="266.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="168.0" minWidth="10.0" prefWidth="168.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints fillHeight="false" maxHeight="-Infinity" minHeight="10.0" prefHeight="50.0" vgrow="SOMETIMES" />
<RowConstraints fillHeight="false" maxHeight="-Infinity" minHeight="5.0" prefHeight="50.0" vgrow="SOMETIMES" />
<RowConstraints fillHeight="false" maxHeight="-Infinity" minHeight="10.0" prefHeight="50.0" vgrow="SOMETIMES" />
<RowConstraints fillHeight="false" maxHeight="-Infinity" minHeight="10.0" prefHeight="50.0" vgrow="SOMETIMES" />
<RowConstraints fillHeight="false" maxHeight="-Infinity" minHeight="5.0" prefHeight="50.0" vgrow="SOMETIMES" />
<RowConstraints fillHeight="false" maxHeight="-Infinity" minHeight="5.0" prefHeight="50.0" vgrow="SOMETIMES" />
<RowConstraints fillHeight="false" maxHeight="-Infinity" minHeight="10.0" prefHeight="50.0" vgrow="SOMETIMES" />
<RowConstraints fillHeight="false" maxHeight="-Infinity" minHeight="10.0" prefHeight="50.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<JFXTextField focusColor="#999ea1" promptText="Email" style="-fx-text-inner-color: #999ea1;" unFocusColor="#474b4f" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<JFXPasswordField focusColor="#999ea1" labelFloat="true" promptText="Password" style="-fx-text-inner-color: #999ea1;" unFocusColor="#474b4f" GridPane.columnIndex="1" GridPane.rowIndex="5" />
<Text fill="WHITE" lineSpacing="50.0" pickOnBounds="true" smooth="false" strokeWidth="0.0" text="Login" textAlignment="CENTER" wrappingWidth="265.443359375" GridPane.columnIndex="1" GridPane.rowIndex="1">
<font>
<Font name="Arial Bold" size="34.0" />
</font>
</Text>
<GridPane GridPane.columnIndex="1" GridPane.rowIndex="7">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<JFXButton alignment="TOP_CENTER" prefHeight="25.0" prefWidth="135.0" ripplerFill="#979797" text="Cancel" textFill="WHITE" />
<JFXButton alignment="TOP_CENTER" prefHeight="25.0" prefWidth="137.0" ripplerFill="#86c232" style="-fx-background-color: #61892F;" text="Login" textFill="WHITE" GridPane.columnIndex="1" />
</children>
</GridPane>
<JFXSpinner prefHeight="22.0" prefWidth="198.0" GridPane.columnIndex="1" GridPane.rowIndex="6">
<effect>
<Lighting>
<bumpInput>
<Shadow />
</bumpInput>
<light>
<Light.Distant />
</light>
</Lighting>
</effect>
</JFXSpinner>
</children>
</GridPane>
</center>
</BorderPane>
堆栈跟踪:
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: javafx.fxml.LoadException:
file:/C:/Users/User/Documents/NetBeansProjects/ JavaFXApplication2/dist/run966830135/JavaFXApplication2.jar!/login.fxml
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2848)
at javafx.fxml.FXMLLoader.processImport(FXMLLoader.java:2692)
at javafx.fxml.FXMLLoader.processProcessingInstruction(FXMLLoader.java:2661)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2517)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at Main.start(Main.java:21)
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
Caused by: java.lang.ClassNotFoundException: com.jfoenix.controls.JFXButton
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at javafx.fxml.FXMLLoader.loadTypeForPackage(FXMLLoader.java:2916)
at javafx.fxml.FXMLLoader.loadType(FXMLLoader.java:2905)
at javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2846)
... 20 more
Exception running application Main
Java Result: 1
您已经将Jfoenix API导入到scenebuilder中,但没有将其包含到项目的构建路径中。
将JAR文件添加到项目中的确切方法取决于IDE。你可以做一个快速的谷歌,并找到它自己。
在下面的代码中编辑Player类,以便代码给出预期的输出。不要只打印预期的输出。不要编辑比赛类。不允许在Player类中添加任何变量。只添加必要的方法。您的代码会给出与预期输出完全相同的输出吗?解释原因。
我是 Vert.x 的新手,我对如何运行\部署 Vert.x 应用程序有点困惑。 我习惯于使用一个带有static main()方法的主类来编写服务器,该方法执行我的所有初始启动代码,例如:连接到DB,读取配置文件,初始化内部服务,最终创建用于接受新连接的侦听套接字。 例如: 现在我的问题是: Vert. x强制我使我的主类扩展Vertube类并覆盖start()方法来初始化监听套接字。 所以现在
本文向大家介绍Java中启动线程start和run的两种方法,包括了Java中启动线程start和run的两种方法的使用技巧和注意事项,需要的朋友参考一下 一、区别 Java中启动线程有两种方法,继承Thread类和实现Runnable接口,由于Java无法实现多重继承,所以一般通过实现Runnable接口来创建线程。但是无论哪种方法都可以通过start()和run()方法来启动线程,下面就来介绍
本文向大家介绍Thread 类中的start() 和 run() 方法有什么区别?相关面试题,主要包含被问及Thread 类中的start() 和 run() 方法有什么区别?时的应答技巧和注意事项,需要的朋友参考一下 start()方法可以用来启动线程,调用该方法,会创建一个新的线程,然后内部执行run()方法;不能多次调用,否则会抛异常 直接调用run()方法,不会创建新的线程;可以进行多次调
本文向大家介绍使用 iisweb.vbs start 启动网站的方法,包括了使用 iisweb.vbs start 启动网站的方法的使用技巧和注意事项,需要的朋友参考一下 应用到: Windows Server 2003, Windows Server 2003 R2, Windows Server 2003 with SP1 IIS 在创建网站时自动将其启动,除非管理员用 /dontstart
问题背景 在做二分查找相关算法题的时候,发现很多人喜欢使用start+(end-start)/2来查找中间值,而不是常见的(start+end)/2,查阅资料,发现start+(end-start)/2可以有效避免int越界问题,但是不知道为什么,希望有大佬可以说一下原理