应用程序启动方法javafx gui中的异常 [英] Exception in Application start method javafx gui

查看:59
本文介绍了应用程序启动方法javafx gui中的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断收到此错误 应用程序启动方法异常 java.lang.reflect.InvocationTargetException

I keep getting this error Exception in Application start method java.lang.reflect.InvocationTargetException

细节

应用程序启动方法java.lang.reflect.InvocationTargetException中的异常,位于 sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)位于 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:498)在 com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389) 在 com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:498)在 sun.launcher.LauncherHelper $ FXHelper.main(LauncherHelper.java:767) 由以下原因引起:java.lang.RuntimeException:应用程序启动中的异常 方法 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:/用户/Suleman/文档/工作区/建模%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)在 javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)在 javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)在 javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)在 javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)在 javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)在 javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)在 javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)在 dcs.rana.muhammad.suleman.SIMULATIONLAB01.App.start(App.java:25)位于 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(本机方法)在 com.sun.javafx.application.PlatformImpl.lambda $ runLater $ 174(PlatformImpl.java:294) 在 com.sun.glass.ui.InvokeLaterDispatcher $ Future.run(InvokeLaterDispatcher.java:95) 在com.sun.glass.ui.win.WinApplication._runLoop(本机方法)处 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位于 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)在 javafx.fxml.FXMLLoader.injectFields(FXMLLoader.java:1163)在 javafx.fxml.FXMLLoader.access $ 1600(FXMLLoader.java:103)在 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个

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$155(LauncherImpl.java:182) at java.lang.Thread.run(Thread.java:745) Caused by: javafx.fxml.LoadException: /C:/Users/Suleman/Documents/workspace/modeling%20and%20simulation/lab01/SIMULATIONLAB01/target/classes/dcs/rana/muhammad/suleman/SIMULATIONLAB01/test.fxml:13 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 dcs.rana.muhammad.suleman.SIMULATIONLAB01.App.start(App.java:25) 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) ... 1 more Caused by: java.lang.IllegalArgumentException: Can not set javafx.scene.control.TableColumn field dcs.rana.muhammad.suleman.SIMULATIONLAB01.controller.normal to javafx.scene.control.Button at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167) at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171) at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81) at java.lang.reflect.Field.set(Field.java:764) 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

我的代码

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文件

and the test.fxml file

<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>

请有人说明可以做什么

推荐答案

在FXML中,您拥有

<Button fx:id="normal" layoutX="70.0" layoutY="213.0" mnemonicParsing="false" onAction="#Normal" prefHeight="25.0" prefWidth="99.0" text="Normal" />

并且在您的控制器中,您拥有

and in your controller, you have

@FXML
TableColumn normal;

因此,错误消息并不奇怪:

So the error message, not surprisingly, says:

无法将javafx.scene.control.TableColumn字段dcs.rana.muhammad.suleman.SIMULATIONLAB01.controller.normal设置为javafx.scene.control.Button

这篇关于应用程序启动方法javafx gui中的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆