有人可以看看我的代码吗?这一切都在昨天工作正常,但似乎我以某种方式做了一个小的改变,刹车代码。不幸的是我无法找到它。
这是我在编译时遇到的错误:
ant -f "C:\\Users\\rezagholifa\\Documents\\NetBeansProjects\\Uhren Konfiguration" jfxsa-run
init:
deps-clean:
Updating property file: C:\Users\rezagholifa\Documents\NetBeansProjects\Uhren Konfiguration\build\built-clean.properties
Deleting directory C:\Users\rezagholifa\Documents\NetBeansProjects\Uhren Konfiguration\build
clean:
init:
deps-jar:
Created dir: C:\Users\rezagholifa\Documents\NetBeansProjects\Uhren Konfiguration\build
Updating property file: C:\Users\rezagholifa\Documents\NetBeansProjects\Uhren Konfiguration\build\built-jar.properties
Created dir: C:\Users\rezagholifa\Documents\NetBeansProjects\Uhren Konfiguration\build\classes
Created dir: C:\Users\rezagholifa\Documents\NetBeansProjects\Uhren Konfiguration\build\empty
Created dir: C:\Users\rezagholifa\Documents\NetBeansProjects\Uhren Konfiguration\build\generated-sources\ap-source-output
Compiling 2 source files to C:\Users\rezagholifa\Documents\NetBeansProjects\Uhren Konfiguration\build\classes
Note: C:\Users\rezagholifa\Documents\NetBeansProjects\Uhren Konfiguration\src\core\FXMLDocumentController.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Copying 3 files to C:\Users\rezagholifa\Documents\NetBeansProjects\Uhren Konfiguration\build\classes
compile:
Created dir: C:\Users\rezagholifa\Documents\NetBeansProjects\Uhren Konfiguration\dist
Detected JavaFX Ant API version 1.3
Launching <fx:jar> task from C:\Program Files\Java\jdk1.8.0_65\jre\..\lib\ant-javafx.jar
Warning: From JDK7u25 the Codebase manifest attribute should be used to restrict JAR repurposing.
Please set manifest.custom.codebase property to override the current default non-secure value '*'.
Launching <fx:deploy> task from C:\Program Files\Java\jdk1.8.0_65\jre\..\lib\ant-javafx.jar
No base JDK. Package will use system JRE.
No base JDK. Package will use system JRE.
jfx-deployment-script:
jfx-deployment:
jar:
Copying 12 files to C:\Users\rezagholifa\Documents\NetBeansProjects\Uhren Konfiguration\dist\run714342489
jfx-project-run:
Executing C:\Users\rezagholifa\Documents\NetBeansProjects\Uhren Konfiguration\dist\run714342489\Uhren Konfiguration.jar using platform C:\Program Files\Java\jdk1.8.0_65\jre/bin/java
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:497)
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:497)
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$156(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException:
file:/C:/Users/rezagholifa/Documents/NetBeansProjects/Uhren%20Konfiguration/dist/run714342489/Uhren%20Konfiguration.jar!/core/FXMLDocument.fxml
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
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 core.Main.start(Main.java:31)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(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$149(WinApplication.java:191)
... 1 more
Caused by: java.lang.NullPointerException
at core.FXMLDocumentController.initialize(FXMLDocumentController.java:211)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
... 17 more
Exception running application core.Main
Java Result: 1
Deleting directory C:\Users\rezagholifa\Documents\NetBeansProjects\Uhren Konfiguration\dist\run714342489
jfxsa-run:
BUILD SUCCESSFUL (total time: 4 seconds)
这是我程序的结构:
src
core
FXMLDocument
FXMLDocumentController
Main.java
img
icon.png
logo.png
FXMLDocument:
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Accordion?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckMenuItem?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.Slider?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.input.KeyCodeCombination?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.text.Font?>
<BorderPane id="BorderPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="core.FXMLDocumentController">
<top>
<MenuBar BorderPane.alignment="CENTER">
<menus>
<Menu mnemonicParsing="false" text="Datei">
<items>
<MenuItem mnemonicParsing="false" onAction="#aboutAction" text="Über">
<accelerator>
<KeyCodeCombination alt="DOWN" code="F1" control="UP" meta="UP" shift="UP" shortcut="UP" />
</accelerator>
</MenuItem>
<MenuItem mnemonicParsing="false" onAction="#quitAction" text="Beenden">
<accelerator>
<KeyCodeCombination alt="DOWN" code="F4" control="UP" meta="UP" shift="UP" shortcut="UP" />
</accelerator>
</MenuItem>
</items>
</Menu>
<Menu mnemonicParsing="false" text="Funktionen">
<items>
<Menu mnemonicParsing="false" text="Ziel-Uhren">
<items>
<CheckMenuItem fx:id="clockMenuItem1" mnemonicParsing="false" selected="true" text="Mechanik">
<accelerator>
<KeyCodeCombination alt="UP" code="DIGIT1" control="UP" meta="UP" shift="DOWN" shortcut="UP" />
</accelerator>
</CheckMenuItem>
<CheckMenuItem fx:id="clockMenuItem2" mnemonicParsing="false" selected="true" text="Elektronik">
<accelerator>
<KeyCodeCombination alt="UP" code="DIGIT2" control="UP" meta="UP" shift="DOWN" shortcut="UP" />
</accelerator>
</CheckMenuItem>
<CheckMenuItem fx:id="clockMenuItem3" mnemonicParsing="false" selected="true" text="Werkstatt">
<accelerator>
<KeyCodeCombination alt="UP" code="DIGIT3" control="UP" meta="UP" shift="DOWN" shortcut="UP" />
</accelerator>
</CheckMenuItem>
<CheckMenuItem fx:id="clockMenuItem4" mnemonicParsing="false" selected="true" text="Schulungsraum">
<accelerator>
<KeyCodeCombination alt="UP" code="DIGIT4" control="UP" meta="UP" shift="DOWN" shortcut="UP" />
</accelerator>
</CheckMenuItem>
<CheckMenuItem fx:id="clockMenuItem5" mnemonicParsing="false" selected="true" text="Aufenthaltsraum">
<accelerator>
<KeyCodeCombination alt="UP" code="DIGIT5" control="UP" meta="UP" shift="DOWN" shortcut="UP" />
</accelerator>
</CheckMenuItem>
</items>
</Menu>
<MenuItem mnemonicParsing="false" onAction="#getTimeAction" text="Hole Zeit von PC">
<accelerator>
<KeyCodeCombination alt="DOWN" code="T" control="UP" meta="UP" shift="UP" shortcut="UP" />
</accelerator>
</MenuItem>
<MenuItem mnemonicParsing="false" text="Update..." />
</items>
</Menu>
</menus>
</MenuBar>
</top>
<center>
<ImageView pickOnBounds="true" preserveRatio="true" BorderPane.alignment="CENTER">
<image>
<Image url="@../img/logo.png" />
</image>
</ImageView>
</center>
<bottom>
<Accordion BorderPane.alignment="CENTER">
<panes>
<TitledPane contentDisplay="CENTER" text="Nachricht" underline="true" wrapText="true">
<content>
<AnchorPane>
<children>
<TextArea fx:id="messageTextArea1" focusTraversable="false" layoutX="24.0" layoutY="25.0" prefHeight="25.0" prefWidth="200.0" promptText="Nachricht">
<font>
<Font name="Frutiger LT Com 45 Light" size="12.0" />
</font>
<opaqueInsets>
<Insets />
</opaqueInsets>
</TextArea>
<Button layoutX="24.0" layoutY="94.0" mnemonicParsing="false" onAction="#messageAction" prefHeight="35.0" prefWidth="200.0" text="Nachricht anzeigen!" textAlignment="CENTER">
<font>
<Font name="Frutiger LT Com 57 Condensed" size="14.0" />
</font>
</Button>
<TextArea fx:id="timeTextArea1" focusTraversable="false" layoutX="24.0" layoutY="55.0" prefHeight="25.0" prefWidth="200.0" promptText="Anzeigedauer [in Sekunden]">
<font>
<Font name="Frutiger LT Com 45 Light" size="12.0" />
</font>
<opaqueInsets>
<Insets />
</opaqueInsets>
</TextArea>
</children>
</AnchorPane>
</content>
</TitledPane>
<TitledPane contentDisplay="CENTER" text="Zeit" underline="true" wrapText="true">
<content>
<AnchorPane>
<children>
<TextArea fx:id="hourTextArea1" focusTraversable="false" layoutX="24.0" layoutY="34.0" prefHeight="14.0" prefWidth="93.0" promptText="Stunde">
<font>
<Font name="Frutiger LT Com 45 Light" size="12.0" />
</font>
<opaqueInsets>
<Insets />
</opaqueInsets>
</TextArea>
<TextArea fx:id="minuteTextArea1" focusTraversable="false" layoutX="130.0" layoutY="33.0" prefHeight="25.0" prefWidth="93.0" promptText="Minute">
<font>
<Font name="Frutiger LT Com 45 Light" size="12.0" />
</font>
</TextArea>
<Label alignment="CENTER" layoutX="117.0" layoutY="38.0" prefHeight="27.0" prefWidth="14.0" style=" " text=":" textAlignment="CENTER" wrapText="false">
<font>
<Font size="18.0" />
</font>
</Label>
<Button layoutX="24.0" layoutY="72.0" mnemonicParsing="false" onAction="#timeAction" prefHeight="35.0" prefWidth="200.0" text="Zeit einstellen!" textAlignment="CENTER">
<font>
<Font name="Frutiger LT Com 57 Condensed" size="14.0" />
</font>
</Button>
</children>
</AnchorPane>
</content>
</TitledPane>
<TitledPane contentDisplay="CENTER" text="Farbe" underline="true" wrapText="true">
<content>
<AnchorPane>
<children>
<ChoiceBox fx:id="colorChoiceBox1" layoutX="24.0" layoutY="29.0" prefWidth="200.0" />
<Button layoutX="24.0" layoutY="69.0" mnemonicParsing="false" onAction="#colorAction" prefHeight="35.0" prefWidth="200.0" text="Farbe einstellen!" textAlignment="CENTER">
<font>
<Font name="Frutiger LT Com 57 Condensed" size="14.0" />
</font>
</Button>
</children>
</AnchorPane>
</content>
</TitledPane>
<TitledPane contentDisplay="CENTER" text="Lautstärke" underline="true" wrapText="true">
<content>
<AnchorPane>
<children>
<Button layoutX="24.0" layoutY="67.0" mnemonicParsing="false" onAction="#volumeAction" prefHeight="35.0" prefWidth="200.0" text="Lautstärke einstellen!" textAlignment="CENTER">
<font>
<Font name="Frutiger LT Com 57 Condensed" size="14.0" />
</font>
</Button>
<Slider fx:id="volumeSlider1" layoutX="22.0" layoutY="23.0" majorTickUnit="20.0" minorTickCount="10" prefHeight="38.0" prefWidth="205.0" showTickLabels="true" showTickMarks="true" snapToTicks="true" value="50.0" />
</children>
</AnchorPane>
</content>
</TitledPane>
</panes>
</Accordion>
</bottom>
</BorderPane>
FXMLDocumentController:
package core;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.CheckMenuItem;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Slider;
import javafx.scene.control.TextArea;
public class FXMLDocumentController implements Initializable {
ObservableList<String> colorsObservableList = FXCollections.observableArrayList("Rot", "Orange", "Grün");
public static String versionString = "v1.3.1";
@FXML
private ChoiceBox colorChoiceBox;
@FXML
private Slider volumeSlider;
@FXML
private TextArea hourTextArea;
@FXML
private TextArea minuteTextArea;
@FXML
private TextArea messageTextArea;
@FXML
private TextArea timeTextArea;
@FXML
private CheckMenuItem clockMenuItem1;
@FXML
private CheckMenuItem clockMenuItem2;
@FXML
private CheckMenuItem clockMenuItem3;
@FXML
private CheckMenuItem clockMenuItem4;
@FXML
private CheckMenuItem clockMenuItem5;
@FXML
private void messageAction(ActionEvent event) throws IOException {
try {
int t = Integer.parseInt(timeTextArea.getText());
if ((t > 0 && t <= 36000) && (messageTextArea.getText().length() != 0)) {
System.out.println("TBI - Message");
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle("Bestätigung");
alert.setHeaderText("Nachricht versendet!");
alert.setContentText("Das Paket wurde erfolgreich versendet :)");
alert.showAndWait();
} else {
throw new RuntimeException();
}
} catch (RuntimeException e) {
messageTextArea.setText("");
timeTextArea.setText("");
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Fehler!");
alert.setHeaderText("Ein Fehler ist aufgetreten");
alert.setContentText("Bei der Umwandlung der Eingaben ist ein Fehler aufgetreten.\nHaben Sie unzulässige Zeichen eingegeben?\nDer Maximalwert für den Timer beträgt 36000.");
alert.showAndWait();
}
}
@FXML
private void timeAction(ActionEvent event) throws IOException {
try {
// check if input can be converted to int
int h = Integer.parseInt(hourTextArea.getText());
int m = Integer.parseInt(minuteTextArea.getText());
// check if both integers are not longer than two digits, that h is
// smaller or equal 12 and that m is smaller than or equal 59
if ((Integer.toString(h).length() <= 2 && Integer.toString(m).length() <= 2) && (h <= 24 && m <= 59)) {
//System.out.println(hour.getText() + ":" + minute.getText());
broadcast(h, m);
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle("Bestätigung");
alert.setHeaderText("Zeit gestellt!");
alert.setContentText("Das Paket wurde erfolgreich versendet :)");
alert.showAndWait();
} else {
// throw RuntimeException if the input could not be converted
throw new RuntimeException();
}
} catch (RuntimeException e) {
//reset input values
hourTextArea.setText("");
minuteTextArea.setText("");
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Fehler!");
alert.setHeaderText("Ein Fehler ist aufgetreten");
alert.setContentText("Bei der Umwandlung der Eingaben ist ein Fehler aufgetreten.\nHaben Sie unzulässige Zeichen eingegeben?");
alert.showAndWait();
}
}
@FXML
private void aboutAction(ActionEvent event) {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Über");
alert.setHeaderText("AG Uhrzeit stellen");
alert.setContentText("Dises Programm sendet auf Port 12345 einen UDP-Broadcast, nach dem alle Uhren in der AG neu gestellt werden.\n\nVersion:\t" + versionString + "\n\nCopyright © 2016");
alert.showAndWait();
}
@FXML
private void getTimeAction(ActionEvent event) throws IOException {
hourTextArea.setText("");
minuteTextArea.setText("");
hourTextArea.setText(new SimpleDateFormat("HH").format(Calendar.getInstance().getTime()));
minuteTextArea.setText(new SimpleDateFormat("mm").format(Calendar.getInstance().getTime()));
}
@FXML
private void beepAction(ActionEvent event) throws IOException {
System.out.println("TBI - Beep");
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle("Bestätigung");
alert.setHeaderText("Beep wird abgespielt!");
alert.setContentText("Das Paket wurde erfolgreich versendet :)");
alert.showAndWait();
}
@FXML
private void marioAction(ActionEvent event) throws IOException {
System.out.println("TBI - Mario");
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle("Bestätigung");
alert.setHeaderText("Mario Theme wird abgespielt!");
alert.setContentText("Das Paket wurde erfolgreich versendet :)");
alert.showAndWait();
}
@FXML
private void colorAction(ActionEvent event) throws IOException {
System.out.println("TBI - >Color");
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle("Bestätigung");
alert.setHeaderText("Farbe eingestellt!");
alert.setContentText("Das Paket wurde erfolgreich versendet :)");
alert.showAndWait();
}
@FXML
private void volumeAction(ActionEvent event) throws IOException {
System.out.println("TBI - >Volume");
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle("Bestätigung");
alert.setHeaderText("Lautstärke eingestellt!");
alert.setContentText("Das Paket wurde erfolgreich versendet :)");
alert.showAndWait();
}
// TODO
public static void broadcast(int h, int m) throws IOException {
DatagramSocket datagramSocket = null;
try {
datagramSocket = new DatagramSocket();
} catch (SocketException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
String test = h + ":" + m;
byte[] buffer = test.getBytes();
InetAddress receiverAddress = InetAddress.getLocalHost();
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, receiverAddress, 80);
datagramSocket.send(packet);
}
@FXML
private void quitAction(ActionEvent event) {
System.exit(0);
}
@Override
public void initialize(URL url, ResourceBundle rb) {
colorChoiceBox.setValue("Rot");
colorChoiceBox.setItems(colorsObservableList);
}
}
Main.java: 包核心;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
public class Main extends Application {
public static String appTitle = "Uhren Konfiguration";
@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.setTitle(appTitle);
//stage.setResizable(false);
stage.getIcons().add(new Image("img/icon.png"));
stage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
答案 0 :(得分:0)
NullPointerException
行211
FXMLDocumentController.initialize