Java运行时错误以及加载异常错误

如何解决Java运行时错误以及加载异常错误

您好,当我尝试运行在oracle场景构建器中创建的fxml文件时遇到此错误,该fxml文件使用每个按钮的正确名称以及正确标记的控制器类进行了标记,我的控制代码问题中的错误看起来像这样

package prog24178;


import javafx.collections.FXCollections;
import java.util.ArrayList;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;

import javafx.scene.control.TextField;
import javafx.scene.control.Alert.AlertType;
import java.io.File;
import java.io.PrintWriter;
import java.util.Scanner;



import javafx.scene.control.ListView;


public class DataBaseController implements Config{
    @FXML TextField txt1,txt2,txt3,txt4;
    @FXML Button b1,b2,b3,b4,b5;
    @FXML ListView<String> list;
    @FXML private ArrayList<String> stringItems = new ArrayList<String>();
    @FXML private ArrayList<Item> items = new ArrayList<Item>();
    
    @FXML
    public void add(ActionEvent e) {
            int id = Integer.parseInt(txt1.getText());
            String item = txt2.getText();
            int quantity = Integer.parseInt(txt3.getText());
            double price = Double.parseDouble(txt4.getText());
            items.add(new Item(id,item,quantity,price));
            list.getItems().clear();
            stringItems.clear();
            for(Item item1 : items) stringItems.add(item1.toString());
            ObservableList<String> items = FXCollections.observableArrayList(stringItems);
            list.setItems(items);
    }
    
    @FXML
    public void load(ActionEvent e) {
        items.clear();
        stringItems.clear();
        list.getItems().clear();
        
        File f = new File(FILE);
        try {
            if(!f.exists()) f.createNewFile();
            Scanner lines = new Scanner(f);
            if(!lines.hasNextLine()) {
                 Alert alert = new Alert(AlertType.INFORMATION,"data file is empty\nenter car and click the save button"); 
                 alert.showAndWait();
            }
            else {
                while(lines.hasNextLine()) {
                    Scanner line = new Scanner(lines.nextLine());
                    line.useDelimiter(":\\s*");
                    items.add(new Item(line.nextInt(),line.next(),line.nextInt(),line.nextDouble()));
                    line.close();
                }
            }
            lines.close();
            
            for(Item item1 : items) 
                list.getItems().add(item1.toString());
                //stringCars.add(car.toString());
            //ObservableList<String> items = FXCollections.observableArrayList(stringCars);
            //list.setItems(items);
            
        } catch (Exception e1) {
            e1.printStackTrace();
        }

    }
    
    @FXML   
        public void save(ActionEvent e)  {
        File f = new File(FILE);
        try {
            if(!f.exists()) f.createNewFile();
            PrintWriter pw = new PrintWriter(f);
            for(Item c : items) 
                pw.printf("%s:%s:%s:%d:%b\n",c.getID(),c.getItem(),c.getQuantity(),c.getPrice());
            pw.close();
        } catch (Exception e1) {
            e1.printStackTrace();
        }
         Alert alert = new Alert(AlertType.INFORMATION,"data is saved in a file\nyou can close the \napplication now"); 
         alert.showAndWait();
    
    }
    @FXML
        public void modify(ActionEvent e)  {
    

        }
    
    @FXML
        public void remove(ActionEvent e)  {
            
        }
        
        }
    
    

RunApp类

package prog24178;

import java.net.URL;

import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class RunApp extends javafx.application.Application implements Config{
    public static void main(String[] args) {
        launch(args);
    }
    @Override
    public void start(Stage ps) throws Exception {
        URL res = this.getClass().getResource("control.fxml");
        Parent scene = FXMLLoader.load(res);
        Scene ourscene = new Scene(scene);
        ps.setScene(ourscene);
        ps.setTitle("Items Database");
        ps.show();
    }
}

已实现的配置界面

以及完整的错误消息

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$1(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:748)
Caused by: javafx.fxml.LoadException: Error resolving onAction='add',either the event handler is not in the Namespace or there is an error in the script.
/C:/Users/Canada%20Computers/workspace/Assign6/bin/prog24178/control.fxml:44

    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2597)
    at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:103)
    at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(FXMLLoader.java:610)
    at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:770)
    at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2823)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2532)
    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 prog24178.RunApp.start(RunApp.java:17)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(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$4(WinApplication.java:186)
    ... 1 more
Exception running application prog24178.RunApp

FXML代码

    <?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.text.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>

<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="384.0" prefWidth="664.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="prog24178.RunApp">
  <columnConstraints>
    <ColumnConstraints hgrow="SOMETIMES" maxWidth="130.0" minWidth="10.0" prefWidth="51.0" />
    <ColumnConstraints hgrow="SOMETIMES" maxWidth="276.0" minWidth="10.0" prefWidth="34.0" />
      <ColumnConstraints hgrow="SOMETIMES" maxWidth="253.0" minWidth="0.0" prefWidth="39.0" />
      <ColumnConstraints hgrow="SOMETIMES" maxWidth="307.0" minWidth="10.0" prefWidth="203.0" />
      <ColumnConstraints hgrow="SOMETIMES" maxWidth="446.0" minWidth="10.0" prefWidth="66.0" />
      <ColumnConstraints hgrow="SOMETIMES" maxWidth="446.0" minWidth="10.0" prefWidth="75.0" />
      <ColumnConstraints hgrow="SOMETIMES" maxWidth="446.0" minWidth="10.0" prefWidth="51.0" />
      <ColumnConstraints hgrow="SOMETIMES" maxWidth="446.0" minWidth="10.0" prefWidth="148.0" />
  </columnConstraints>
  <rowConstraints>
    <RowConstraints />
      <RowConstraints maxHeight="48.0" minHeight="10.0" prefHeight="48.0" />
    <RowConstraints maxHeight="48.0" minHeight="0.0" prefHeight="40.0" />
    <RowConstraints maxHeight="44.0" minHeight="8.0" prefHeight="32.0" vgrow="SOMETIMES" />
      <RowConstraints maxHeight="274.0" minHeight="10.0" prefHeight="32.0" vgrow="SOMETIMES" />
      <RowConstraints maxHeight="274.0" minHeight="10.0" prefHeight="201.0" vgrow="SOMETIMES" />
      <RowConstraints maxHeight="123.0" minHeight="10.0" prefHeight="31.0" vgrow="SOMETIMES" />
  </rowConstraints>
   <children>
      <Label alignment="CENTER_RIGHT" text="ID:" GridPane.halignment="CENTER" GridPane.rowIndex="2" />
      <TextField fx:id="txt1" prefHeight="25.0" prefWidth="46.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
      <Label text="Item:" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="2" />
      <TextField fx:id="txt2" GridPane.columnIndex="3" GridPane.rowIndex="2" />
      <Label prefHeight="17.0" prefWidth="57.0" text="Quanitity:" GridPane.columnIndex="4" GridPane.halignment="CENTER" GridPane.rowIndex="2" />
      <TextField fx:id="txt3" GridPane.columnIndex="5" GridPane.rowIndex="2" />
      <Label text="Price:" GridPane.columnIndex="6" GridPane.halignment="CENTER" GridPane.rowIndex="2" />
      <TextField fx:id="txt4" GridPane.columnIndex="7" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets />
         </GridPane.margin>
      </TextField>
      <HBox prefHeight="29.0" prefWidth="516.0" spacing="10.0" GridPane.columnIndex="3" GridPane.columnSpan="2147483647" GridPane.rowIndex="3">
         <children>
            <Button fx:id="b1" mnemonicParsing="false" onAction="add" text="Add Item" />
            <Button fx:id="b2" mnemonicParsing="false" onAction="#modify" text="Modify Item" />
            <Button fx:id="b3" mnemonicParsing="false" onAction="#remove" prefHeight="25.0" prefWidth="107.0" text="Remove Item" />
         </children>
         <GridPane.margin>
            <Insets top="10.0" />
         </GridPane.margin>
      </HBox>
      <HBox prefHeight="100.0" prefWidth="200.0" GridPane.columnSpan="2147483647" GridPane.rowIndex="5">
         <children>
            <ListView fx:id="list" prefHeight="201.0" prefWidth="627.0">
               <padding>
                  <Insets left="20.0" right="10.0" />
               </padding>
            </ListView>
         </children>
      </HBox>
      <Label text="Items:" GridPane.halignment="CENTER" GridPane.rowIndex="4" />
      <HBox prefHeight="100.0" prefWidth="200.0" spacing="10.0" GridPane.columnIndex="3" GridPane.columnSpan="2147483647" GridPane.rowIndex="6">
         <children>
            <Button fx:id="b4" mnemonicParsing="false" onAction="#load" text="Load Data From File" />
            <Button fx:id="b5" mnemonicParsing="false" onAction="#save" text="Save Data To File" />
         </children>
      </HBox>
      <HBox prefHeight="100.0" prefWidth="200.0" GridPane.columnIndex="3" GridPane.columnSpan="2147483647" GridPane.rowIndex="1">
         <children>
            <Label alignment="CENTER" prefHeight="48.0" prefWidth="318.0" text="Database of Items">
               <font>
                  <Font size="26.0" />
               </font>
            </Label>
         </children>
      </HBox>
   </children>
   <opaqueInsets>
      <Insets />
   </opaqueInsets>
</GridPane>

        

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-