下面是main方法的代码...
package com.troyfirstgluonfxapplication;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
/**
*
* @author tfrericks
*/
public class TroyFirstGluonFXApplication extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
这是控制器的代码...
package com.troyfirstgluonfxapplication;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
/**
*
* @author tfrericks
*/
public class FXMLDocumentController implements Initializable {
@FXML
private Label label;
@FXML
private void handleButtonAction(ActionEvent event) {
System.out.println("You clicked me!");
label.setText("Hello World!");
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
下面是fxml...
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.troyfirstgluonfxapplication.FXMLDocumentController">
<children>
<Button layoutX="126" layoutY="90" text="Click Me!" onAction="#handleButtonAction" fx:id="button" />
<Label layoutX="126" layoutY="120" minHeight="16" minWidth="69" fx:id="label" />
</children>
</AnchorPane>
Executing: gradle run
:compileJava UP-TO-DATE
:compileRetrolambdaMain UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileAndroidJava SKIPPED
:compileRetrolambdaAndroid SKIPPED
:compileTestJava UP-TO-DATE
:compileRetrolambdaTest SKIPPED
:compileRetrolambda UP-TO-DATE
:compileDesktopJava UP-TO-DATE
:processDesktopResources UP-TO-DATE
:desktopClasses UP-TO-DATE
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:483)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.ja va:363)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:303)
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:483)
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:875)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(LauncherImpl .java:157)
at com.sun.javafx.application.LauncherImpl$$Lambda$48/1732398722.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3201)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3169)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3142)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3118)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3098)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3091)
at com.troyfirstgluonfxapplication.TroyFirstGluonFXApplication.start(TroyFirstGluonFXApplication.java:23)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(LauncherImp l.java:821)
at com.sun.javafx.application.LauncherImpl$$Lambda$51/1284648825.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(PlatformImpl.java:3 23)
at com.sun.javafx.application.PlatformImpl$$Lambda$44/1051754451.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/1830989796.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291 )
at com.sun.javafx.application.PlatformImpl$$Lambda$46/1775282465.run(Unknown Source)
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$141(WinApplication.java:102)
at com.sun.glass.ui.win.WinApplication$$Lambda$37/1109371569.run(Unknown Source)
... 1 more
Exception running application com.troyfirstgluonfxapplication.TroyFirstGluonFXApplication
:run FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':run'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_25\bin\java.exe'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or -- debug option to get more log output.
BUILD FAILED
Total time: 2.29 secs
Build failure (see the Notifications window for stacktrace): gradle run
特洛伊。
#
该错误意味着它找不到FXML文件。
在Projects视图的Resources[Main]包下,您应该创建包com.troyfirstgluonfxapplication
,并在其中放置fxmldocument.fxml
文件。
如果检查Files视图,应该有如下内容:
src
|-- main
| |-- java
| | |-- com
| | | |-- troyfirstgluonfxapplication
| | | | |-- TroyFirstGluonFXApplication.java
| | | | |-- FXMLDocumentController.java
| |-- resources
| | |-- com
| | | |-- troyfirstgluonfxapplication
| | | | |-- FXMLDocument.fxml
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Rectangle2D visualBounds = Screen.getPrimary().getVisualBounds();
Scene scene = new Scene(root, visualBounds.getWidth(), visualBounds.getHeight());
stage.setScene(scene);
stage.show();
}
本文向大家介绍使用Vert.x Maven插件快速创建项目的方法,包括了使用Vert.x Maven插件快速创建项目的方法的使用技巧和注意事项,需要的朋友参考一下 本文介绍了使用Vert.x Maven插件快速创建项目的方法,分享给大家,具体如下: 文档地址: https://reactiverse.io/vertx-maven-plugin 已有项目添加该插件 在项目 pom.xml 目录,执行
Hello World 项目创建 如上图标注 1 所示,点击 Create New Project 进入向导式创建项目 如上图标注 1 所示,如果此时 IntelliJ IDEA 还没有配置任何一个 SDK 的话,可以点击 New... 先进行 SDK 的配置。 如上图标注 2 所示,配置好 SDK 或选择好 SDK 之后,点击 Next 进入下一步。 如上图标注 1 所示,可以选择模板快速创建项
我已经从https://eclipse.adobe.com/aem/dev-tools安装了AEM Eclipse插件(我下载了它作为存档,并在我的Eclipse作为本地存档使用)。 然后,我遇到了AEM向导在创建新项目时不显示的问题。找到了从中下载原型目录xml文件的变通方法https://repo.adobe.com/nexus/content/groups/public/archetype-
使用 @vue/cli 推荐用脚手架工具 @vue/cli 来创建一个使用 vue-loader 的项目: npm install -g @vue/cli vue create hello-vue cd hello-vue npm run serve # ready to go!
点击顶部导航右上角"+"按钮,可进入创建项目页。 主要操作步骤: 选择目录:首先在本地文件浏览器中选择需要创建项目的目录,点击创建 选择模板:可选择预置脚手架或自定义脚手架 输入配置:输入项目需要的初始化信息 依赖安装:配置完成后系统会自动执行依赖安装 创建完成 San CLI UI中的文件浏览器可实现功能: 目录切换:可以通过点击路径切换,或者直接点击编辑后输入本地路径 目录收藏:对本地路径进行