我一直收到这个错误 Application start方法中的异常 java.lang.reflect.InvocationTargetException
细节
应用程序启动方法java.lang.reflect.InvocationTargetException中的异常 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:498)at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389) 在 com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:498)at sun.launcher.LauncherHelper $ FXHelper.main(LauncherHelper.java:767) 引起:java.lang.RuntimeException:Application start中的异常 方法 com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917) 在 com.sun.javafx.application.LauncherImpl.lambda $ launchApplication $ 155(LauncherImpl.java:182) 在java.lang.Thread.run(Thread.java:745)引起: javafx.fxml.LoadException: /C:/Users/Suleman/Documents/workspace/modeling%20and%20simulation/lab01/SIMULATIONLAB01/target/classes/dcs/rana/muhammad/suleman/SIMULATIONLAB01/test.fxml:13 在 javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601) 在javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)at at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)at at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)at at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)at at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)at at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)at at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)at at dcs.rana.muhammad.suleman.SIMULATIONLAB01.App.start(App.java:25)at at com.sun.javafx.application.LauncherImpl.lambda $ launchApplication1 $ 162(LauncherImpl.java:863) 在 com.sun.javafx.application.PlatformImpl.lambda $ runAndWait $ 175(PlatformImpl.java:326) 在 com.sun.javafx.application.PlatformImpl.lambda为$ null $ 173(PlatformImpl.java:295) 在java.security.AccessController.doPrivileged(Native Method)at com.sun.javafx.application.PlatformImpl.lambda $ runLater $ 174(PlatformImpl.java:294) 在 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) ... 1更多引起:java.lang.IllegalArgumentException:无法设置 javafx.scene.control.TableColumn字段 dcs.rana.muhammad.suleman.SIMULATIONLAB01.controller.normal to javafx.scene.control.Button at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167) 在 sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171) 在 sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81) 在java.lang.reflect.Field.set(Field.java:764)at javafx.fxml.FXMLLoader.injectFields(FXMLLoader.java:1163)at at javafx.fxml.FXMLLoader.access $ 1600(FXMLLoader.java:103)at at javafx.fxml.FXMLLoader $ ValueElement.processValue(FXMLLoader.java:857) 在 javafx.fxml.FXMLLoader $ ValueElement.processStartElement(FXMLLoader.java:751) 在javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707) 在javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)... 17更多
我的代码
app.java类
public class App extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
// TODO Auto-generated method stub
Parent root = FXMLLoader.load(getClass().getResource("test.fxml"));
Scene scene = new Scene(root);
primaryStage.setTitle("simple");
primaryStage.setScene(scene);
primaryStage.show();
}
}
和控制器类
public class controller {
double quant, og, bound, sprice, cprice, trl, ds;
@FXML
private TextField qt;
@FXML
private TextField org;
@FXML
private TextField bd;
@FXML
private TextField sp;
@FXML
private TextField cp;
@FXML
private TextField tl;
@FXML
private TextField disc;
@FXML
TableColumn normal;
public void getQT(ActionEvent e) {
quant = Double.parseDouble(qt.getText());
System.out.println(quant);
}
public void getOrg(ActionEvent e) {
og = Double.parseDouble(org.getText());
System.out.println(og);
}
public void getBd(ActionEvent e) {
bound = Double.parseDouble(bd.getText());
System.out.println(bound);
}
public void getSP(ActionEvent e) {
sprice = Double.parseDouble(sp.getText());
System.out.println(sprice);
}
public void getCP(ActionEvent e) {
cprice = Double.parseDouble(cp.getText());
System.out.println(cprice);
}
public void getTL(ActionEvent e) {
trl = Double.parseDouble(tl.getText());
System.out.println(trl);
}
public void getDisc(ActionEvent e) {
ds = Double.parseDouble(disc.getText());
System.out.println(ds);
}
public void Random(ActionEvent e) {
qt.setText("Clicked");
}
//@FXML
public void Normal(ActionEvent e) {
//normal.setText(value);
N_profit();
}
public void N_profit() {
//double demand, profit, trl, bound, og, quant, sprice, cprice, ds;
double demand, profit;
int diff;
int[] d_arr = new int[(int) trl + 1];
int[] p_arr = new int[(int) trl + 1];
diff = (int) ((bound - og) / trl);
demand = og;
int j = 1;
while (demand <= bound || demand < bound) {
d_arr[j] = (int)demand;
if (demand <= quant) {
profit = (sprice * demand) - (cprice * quant) + (ds * sprice) * (quant - demand);
p_arr[j] = (int) profit;
profit = 0;
} else {
profit = (sprice * quant) - (cprice * quant);
p_arr[j] = (int) profit;
profit = 0;
}
demand = demand+diff;
j++;
if (j == trl + 1)
break;
//i =i+diff;
}
for (int z = 1; z <= trl ; z++) {
normal.setText("demand" + d_arr[z] + "Profit" + p_arr[z] + "z" + z);
}
}
}
和test.fxml文件
<AnchorPane prefHeight="540.0" prefWidth="593.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="dcs.rana.muhammad.suleman.SIMULATIONLAB01.controller">
<children>
<Button fx:id="normal" layoutX="70.0" layoutY="213.0" mnemonicParsing="false" onAction="#Normal" prefHeight="25.0" prefWidth="99.0" text="Normal" />
<Label layoutX="14.0" layoutY="21.0" prefHeight="25.0" prefWidth="56.0" text="Quantity" />
<TextField fx:id="qt" layoutX="89.0" layoutY="21.0" onAction="#getQT" prefHeight="25.0" prefWidth="121.0" />
<Label layoutX="14.0" layoutY="63.0" text="Selling Price" />
<Label layoutX="244.0" layoutY="106.0" text="Random number Bound" />
<Label layoutX="16.0" layoutY="106.0" text="Cost Price" />
<Label layoutX="244.0" layoutY="22.0" text="Trials" />
<TextField fx:id="sp" layoutX="89.0" layoutY="60.0" onAction="#getSP" prefHeight="25.0" prefWidth="121.0" />
<TextField fx:id="bd" layoutX="389.0" layoutY="102.0" onAction="#getBd" prefHeight="25.0" prefWidth="121.0" />
<TextField fx:id="cp" layoutX="89.0" layoutY="102.0" onAction="#getCP" prefHeight="25.0" prefWidth="121.0" />
<TextField fx:id="tl" layoutX="288.0" layoutY="18.0" onAction="#getTL" prefHeight="25.0" prefWidth="121.0" />
<ScrollPane layoutX="3.0" layoutY="328.0" prefHeight="198.0" prefWidth="587.0">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="200.0">
<children>
<TableView fx:id="mymsg" layoutX="-4.0" prefHeight="200.0" prefWidth="208.0">
<columns>
<TableColumn prefWidth="75.0" text="Demand" />
<TableColumn prefWidth="75.0" text="Profit" />
<TableColumn prefWidth="75.0" />
</columns>
<effect>
<Glow />
</effect>
</TableView>
</children>
</AnchorPane>
</content>
</ScrollPane>
<Label layoutX="242.0" layoutY="63.0" text="Random number origin" />
<TextField fx:id="org" layoutX="389.0" layoutY="59.0" onAction="#getOrg" prefHeight="25.0" prefWidth="121.0" />
<Label layoutX="219.0" layoutY="179.0" prefHeight="34.0" prefWidth="156.0" text=" Distributions">
<font>
<Font name="Arial Bold" size="12.0" />
</font>
</Label>
<Button layoutX="389.0" layoutY="213.0" mnemonicParsing="false" onAction="#Random" prefHeight="25.0" prefWidth="99.0" text="Random" />
<Label layoutX="19.0" layoutY="146.0" text="Discount" />
<TextField fx:id="disc" layoutX="89.0" layoutY="142.0" onAction="#getDisc" prefHeight="25.0" prefWidth="121.0" />
</children>
</AnchorPane>
请有人解释可以做什么
答案 0 :(得分:2)
在你的FXML中,你有
let def = NSUserDefaults.standardUserDefaults()
let current = def.integerForKey("version")
print("Current version is \(current)")
并且在您的控制器中,您有
<Button fx:id="normal" layoutX="70.0" layoutY="213.0" mnemonicParsing="false" onAction="#Normal" prefHeight="25.0" prefWidth="99.0" text="Normal" />
所以错误信息毫不奇怪地说:
无法将
@FXML TableColumn normal;
字段javafx.scene.control.TableColumn
设置为dcs.rana.muhammad.suleman.SIMULATIONLAB01.controller.normal