我已经创建了一个新的JavaFX项目,我可以轻松地运行。
主:
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
BorderPane root = new BorderPane();
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
如果我尝试复制并粘贴一些旧的.fxml
,我会收到一些错误。
fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.BorderPane?>
<BorderPane prefHeight="691.0" prefWidth="668.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.ControllerStart">
<center>
<Pane prefHeight="599.0" prefWidth="668.0" BorderPane.alignment="CENTER">
<children>
<Label layoutX="366.0" layoutY="38.0" text="10:20">
<font>
<Font size="62.0" />
</font>
</Label>
<Label layoutX="359.0" layoutY="111.0" text="00:00:00">
<font>
<Font size="48.0" />
</font>
</Label>
<Label layoutX="35.0" layoutY="66.0" text="Operator code:">
<font>
<Font size="23.0" />
</font>
</Label>
<Label layoutX="111.0" layoutY="101.0" text="000-000-00" />
<CheckBox fx:id="CB_smcProblem" disable="true" layoutX="206.0" layoutY="211.0" mnemonicParsing="false" text="problem" />
<CheckBox fx:id="CB_smcCheck" disable="true" layoutX="205.0" layoutY="242.0" mnemonicParsing="false" text="check" />
<CheckBox fx:id="CB_smc" layoutX="72.0" layoutY="221.0" mnemonicParsing="false" onAction="#SMC_click" text="SMC" />
<CheckBox fx:id="CB_sketch" layoutX="72.0" layoutY="330.0" mnemonicParsing="false" text="Sketch" />
<CheckBox fx:id="CB_sketchProblem" disable="true" layoutX="206.0" layoutY="320.0" mnemonicParsing="false" text="problem" />
<CheckBox fx:id="CB_sketchCheck" disable="true" layoutX="206.0" layoutY="351.0" mnemonicParsing="false" text="check" />
<CheckBox fx:id="CB_configuration" layoutX="72.0" layoutY="457.0" mnemonicParsing="false" text="Configuration" />
<CheckBox fx:id="CB_configurationProblem" disable="true" layoutX="207.0" layoutY="447.0" mnemonicParsing="false" text="problem" />
<CheckBox fx:id="CB_configurationCheck" disable="true" layoutX="207.0" layoutY="478.0" mnemonicParsing="false" text="check" />
<Button fx:id="B_closed" disable="true" layoutX="249.0" layoutY="591.0" mnemonicParsing="false" text="Closed">
<font>
<Font size="35.0" />
</font>
</Button>
<CheckBox fx:id="CB_supportH" layoutX="366.0" layoutY="221.0" mnemonicParsing="false" text="Support on helicopter" />
<CheckBox fx:id="CB_qualityS" layoutX="364.0" layoutY="291.0" mnemonicParsing="false" text="Quality support " />
<CheckBox fx:id="CB_releaseD" layoutX="365.0" layoutY="362.0" mnemonicParsing="false" text="Release of documents" />
<CheckBox fx:id="CB_other" layoutX="368.0" layoutY="515.0" mnemonicParsing="false" text="Other" />
<TextField fx:id="TF_other" editable="false" layoutX="483.0" layoutY="510.0" prefHeight="31.0" prefWidth="136.0" />
<CheckBox fx:id="CB_requestC" layoutX="364.0" layoutY="426.0" mnemonicParsing="false" text="Request ciclie" />
<Button layoutX="112.0" layoutY="613.0" mnemonicParsing="false" onAction="#SMC_click" text="Button" />
</children>
</Pane>
</center>
</BorderPane>
这是对主文件的修改:
...
BorderPane root = new BorderPane(); //old part
root= FXMLLoader.load(getClass().getResource("Start.fxml")); //new part
Scene scene = new Scene(root,400,400); //old part
...
我还添加了一个类ControllerStart.java。
这是我现在运行项目时的错误:
javafx.fxml.LoadException: /C:/eclipse/workspace/neon/TAP1/bin/application/Start.fxml:47
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 application.Main.start(Main.java:15)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$148(WinApplication.java:191)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: Can not set java.awt.TextField field application.ControllerStart.TF_other to javafx.scene.control.TextField
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(Unknown Source)
at java.lang.reflect.Field.set(Unknown Source)
at javafx.fxml.FXMLLoader.injectFields(FXMLLoader.java:1163)
at javafx.fxml.FXMLLoader.access$1600(FXMLLoader.java:103)
at javafx.fxml.FXMLLoader$ValueElement.processValue(FXMLLoader.java:857)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:751)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
... 17 more
答案 0 :(得分:2)
对您有帮助的错误行是:
FPTH="/Users/robertford/PycharmProjects/inference_engine2/inference2/Proofs/prove.py"
vmysql=$(grep "mysql =" $FPTH | cut -d'=' -f2)
vexcel=$(grep “excel =" $FPTH | cut -d'=' -f2)
echo $vexcel
echo $vmysql
if [ "$vexcel" == "True" ] ; then
echo "Excel"
elif [ "$vmysql" = "True" ]
then
echo "Mysql"
else
echo "Django"
fi
if [ "$vexcel" = "True" ] ; then
echo "Excel is set”
python $FPTH
elif [ "$vmysql" = "True" ]
then
echo "Mysql is set”
python $FPTH
else
echo “Django is set”
cd /dUsers/robertford/PycharmProjects/inference_engine2
python manage.py runserver
fi
基本上,您的控制器中有一个名为at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException:
Can not set java.awt.TextField field application.ControllerStart.TF_other to javafx.scene.control.TextField
的字段,它是一个用TF_other
注释的AWT TextField
。当您导入@FXML
时,您可能会错误地导入java.awt.TextField
。
如此有趣的是,您发布的所有代码都无关紧要,而您未发布的代码就是错误所在。