试图在JAVAFX表上显示对象,我得到了java.lang.NullPointerException

试图在JAVAFX表上显示对象,我得到了java.lang.NullPointerException,javafx,tableview,observablelist,Javafx,Tableview,Observablelist,我对第112/113/114行有疑问,程序将在没有它们的情况下编译, 我试图从(ObservableList数据库)中获取数据并将其显示在表中,我试图将变量保留为date,double。将其更改为SimpleDoubleProperty,SimpleObject属性 这是我得到的例外 at com.sun.glass.ui.win.WinApplication.lambda$null$145(Unknown Source) at com.sun.glass.ui.win.Win

我对第112/113/114行有疑问,程序将在没有它们的情况下编译, 我试图从(ObservableList数据库)中获取数据并将其显示在表中,我试图将变量保留为date,double。将其更改为SimpleDoubleProperty,SimpleObject属性

这是我得到的例外

    at com.sun.glass.ui.win.WinApplication.lambda$null$145(Unknown
 Source)    at
 com.sun.glass.ui.win.WinApplication$$Lambda$36/2117255219.run(Unknown
 Source)    ... 1 more Caused by: java.lang.NullPointerException    at
 org.xcellcomm.Controller.initialize(Controller.java:103)   ... 23 more
 Exception running application org.xcellcomm.Start




package org.xcellcomm;


import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.ResourceBundle;


import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;

import javafx.scene.control.TextField;






public class Controller implements Initializable {

     private final ObservableList<Mrc> data =
                FXCollections.observableArrayList();

    Date date;
    ArrayList<Mrc> dailyMRC;

    final static int  VALUEBUNDLE = 5;
    final static int  PHP = 6;
    final static int  BLOCKIT = 1;
    final static int  RHAPSODY = 10;
    final static int  WORLDCALLING = 5;
    final static int  LOOKOUT = 3;



        @FXML
        private CheckBox checkboxFeatureLookout;

        @FXML
        private RadioButton plan40Radio;

        @FXML
        private CheckBox checkboxBlockIt;

        @FXML
        private CheckBox checkboxFeatureValueBundle;

        @FXML
        private TextField textfeildTodayGoal;

        @FXML
        private Button buttonAddActivation;

        @FXML
        private CheckBox checkboxFeatureRhpsody;

        @FXML
        private CheckBox checkboxFeatureWorldCalling;

        @FXML
        private RadioButton plan50Radio;

        @FXML
        private CheckBox checkboxFeaturePhp;

        @FXML
        private RadioButton plan60Radio;

        @FXML
        private TextField textfeildTodayActivations;

        @FXML
        private TableView<Plana> dailyActivationTable;

        @FXML
        private TableColumn<Plana, Date>  dailyActivationTimeColon;

        @FXML
        private TableColumn<Plana, Double> dailyActivationPlanColon;


       private final ObservableList<Plana> database =
              FXCollections.observableArrayList();
        @Override
        public void initialize(URL location, ResourceBundle resources) {
dailyActivationPlanColon = new TableColumn<Controller.Plana, Double>();
dailyActivationTimeColon = new TableColumn<Controller.Plana, Date>();
dailyActivationTable.getColumns().addAll(dailyActivationPlanColon,dailyActivationTimeColon);
            dailyMRC = new ArrayList<>();

            ToggleGroup group = new ToggleGroup();
            plan40Radio.setToggleGroup(group);
            plan50Radio.setToggleGroup(group);
            plan60Radio.setToggleGroup(group);


            dailyActivationPlanColon.setCellValueFactory(new PropertyValueFactory<Plana, Double>("PlanProperty"));
            dailyActivationTimeColon.setCellValueFactory(new PropertyValueFactory<Plana,Date>("dateProperty"));
            dailyActivationTable.setItems(database);


        }


        //Getting input from the GUI and Calculate the MRC Constructor
        private int newActivationCalculater(){
            int mrc=0;
            if(plan40Radio.isSelected())mrc=+40;
            if(plan50Radio.isSelected())mrc=+50;
            if(plan60Radio.isSelected())mrc=+60;
            if(checkboxBlockIt.isSelected())mrc=+BLOCKIT;
            if(checkboxFeatureLookout.isSelected())mrc=+LOOKOUT;
            if(checkboxFeaturePhp.isSelected())mrc=+PHP;
            if(checkboxFeatureRhpsody.isSelected())mrc=+RHAPSODY;
            if(checkboxFeatureValueBundle.isSelected())mrc=+VALUEBUNDLE;
            if(checkboxFeatureWorldCalling.isSelected())mrc=+WORLDCALLING;


            return mrc;
        }

        //Getting the Current time for the mrc constructor
        private Date currentTime(){

            Date date = new Date();
        return date;

        }


        public void buttonAddActivationPressed(){
            if(plan40Radio.isSelected()||plan50Radio.isSelected()||plan60Radio.isSelected()){
        double mrc  = (double)newActivationCalculater();
        Date date = currentTime();
        //Mrc newactivation = ;

        unselectAllItem();

        database.add(new Plana((int)mrc, date));
        todayactivationRefresh();



            }//if end
            else{//if user did not select plan

                Alert alert = new Alert(AlertType.WARNING);
            alert.setTitle("Warning!");
            alert.setHeaderText("Something wrong:)");
            alert.setContentText("You didn't select a Plan");

            alert.showAndWait();}
        }
        void todayactivationRefresh(){
            String todayactivation=dailyMRC.size()+"";
            textfeildTodayActivations.setText(todayactivation);
        }
        void unselectAllItem(){
            plan40Radio.setSelected(false);
            plan50Radio.setSelected(false);
            plan60Radio.setSelected(false);

            checkboxBlockIt.setSelected(false);
            checkboxFeatureLookout.setSelected(false);
            checkboxFeaturePhp.setSelected(false);
            checkboxFeatureValueBundle.setSelected(false);
            checkboxFeatureWorldCalling.setSelected(false);
            checkboxFeatureRhpsody.setSelected(false);


        }

        public  class Plana {// its might not work because it is it's not public

              //  private final SimpleStringProperty dateStringProperty;
                private final SimpleDoubleProperty PlanProperty;
                private final SimpleObjectProperty<Date> dateProperty;





                private Plana( double gPlan, Date gDate) {
                   // this.dateStringProperty = new SimpleStringProperty(gStringDate);
                    this.PlanProperty = new SimpleDoubleProperty(gPlan);
                    this.dateProperty = new SimpleObjectProperty<Date>(gDate);
                }

                /**
                 * @return the dateStringProperty
                 */
            //  public SimpleStringProperty getDateStringProperty() {
                //  return dateStringProperty;
                //}

                /**
                 * @return the planProperty
                 */
                public SimpleDoubleProperty getPlanProperty() {
                    return PlanProperty;
                }

                /**
                 * @return the dateProperty
                 */
                public SimpleObjectProperty<Date> getDateProperty() {
                    return dateProperty;
                }
            }
    }
mainMrc.fxml

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

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

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.xcellcomm.Controller">
   <center>
      <VBox prefHeight="200.0" prefWidth="100.0" BorderPane.alignment="CENTER">
         <children>
            <Label text="Add New Activation :">
               <VBox.margin>
                  <Insets />
               </VBox.margin>
            </Label>
            <HBox prefHeight="100.0" prefWidth="200.0">
               <children>
                  <HBox prefHeight="90.0" prefWidth="200.0">
                     <children>
                        <VBox prefHeight="200.0" prefWidth="100.0">
                           <children>
                              <Label text="Select Plan Rate :" />
                              <RadioButton fx:id="plan40Radio" mnemonicParsing="false" text="40 or less Plan" />
                              <RadioButton fx:id="plan50Radio" mnemonicParsing="false" text="50 Plan" />
                              <RadioButton fx:id="plan60Radio" mnemonicParsing="false" text="60 Plan" />
                              <Region prefHeight="16.0" prefWidth="100.0" />
                              <Button fx:id="buttonAddActivation" mnemonicParsing="false" onAction="#buttonAddActivationPressed" text="Add Activation" />
                           </children>
                        </VBox>
                     </children>
                  </HBox>
                  <VBox prefHeight="102.0" prefWidth="163.0">
                     <children>
                        <Label text="Added Features :" />
                        <CheckBox fx:id="checkboxFeaturePhp" layoutX="10.0" layoutY="27.0" mnemonicParsing="false" text="PHP" />
                        <CheckBox fx:id="checkboxBlockIt" mnemonicParsing="false" text="Block it" />
                        <CheckBox fx:id="checkboxFeatureValueBundle" mnemonicParsing="false" text="Value Bundle" />
                     </children>
                  </VBox>
                  <VBox prefHeight="200.0" prefWidth="100.0">
                     <children>
                        <Label text="                           " />
                        <CheckBox fx:id="checkboxFeatureLookout" mnemonicParsing="false" text="Lookout MS" />
                        <CheckBox fx:id="checkboxFeatureRhpsody" mnemonicParsing="false" text="Rhapsody" />
                        <CheckBox fx:id="checkboxFeatureWorldCalling" mnemonicParsing="false" text="World Calling" />
                     </children>
                  </VBox>
               </children>
            </HBox>
            <Region prefHeight="23.0" prefWidth="600.0" />
            <HBox prefHeight="131.0" prefWidth="580.0">
               <children>
                  <TableView prefHeight="100.0" prefWidth="263.0">
                    <columns>
                      <TableColumn prefWidth="109.0" text="Time" />
                      <TableColumn prefWidth="82.0" text="Plan" />
                    </columns>
                     <HBox.margin>
                        <Insets left="10.0" />
                     </HBox.margin>
                  </TableView>
                  <Region prefHeight="200.0" prefWidth="200.0" HBox.hgrow="ALWAYS" />
                  <TableView prefHeight="100.0" prefWidth="309.0">
                    <columns>
                      <TableColumn prefWidth="147.0" text="Date" />
                      <TableColumn prefWidth="90.0" text="MRC" />
                    </columns>
                     <HBox.margin>
                        <Insets right="10.0" />
                     </HBox.margin>
                  </TableView>
               </children>
            </HBox>
            <Region prefHeight="29.0" prefWidth="580.0" />
            <HBox prefHeight="100.0" prefWidth="200.0">
               <children>
                  <VBox prefHeight="150.0" prefWidth="218.0">
                     <children>
                        <Label text="Today Activations" />
                        <TextField fx:id="textfeildTodayActivations" editable="false" maxWidth="100.0" prefHeight="39.0" prefWidth="100.0" promptText="Activations">
                           <font>
                              <Font size="18.0" />
                           </font>
                        </TextField>
                        <Label text="Today Goal" />
                        <TextField fx:id="textfeildTodayGoal" editable="false" maxWidth="100.0" prefHeight="39.0" prefWidth="100.0" promptText="Goal">
                           <font>
                              <Font size="18.0" />
                           </font>
                        </TextField>
                        <Label text="Current Process" />
                        <ProgressBar prefWidth="200.0" progress="0.0" />
                     </children>
                  </VBox>
                  <Region prefHeight="150.0" prefWidth="80.0" HBox.hgrow="ALWAYS" />
                  <LineChart prefHeight="150.0" prefWidth="281.0">
                    <xAxis>
                      <CategoryAxis side="BOTTOM" />
                    </xAxis>
                    <yAxis>
                      <NumberAxis side="LEFT" />
                    </yAxis>
                  </LineChart>
               </children>
            </HBox>
         </children>
         <BorderPane.margin>
            <Insets left="10.0" right="10.0" />
         </BorderPane.margin>
      </VBox>
   </center>
   <top>
      <MenuBar BorderPane.alignment="CENTER">
        <menus>
          <Menu mnemonicParsing="false" text="File">
            <items>
              <MenuItem mnemonicParsing="false" text="Close" />
            </items>
          </Menu>
          <Menu mnemonicParsing="false" text="Edit">
            <items>
              <MenuItem mnemonicParsing="false" text="Delete" />
            </items>
          </Menu>
          <Menu mnemonicParsing="false" text="Help">
            <items>
              <MenuItem mnemonicParsing="false" text="About" />
            </items>
          </Menu>
        </menus>
      </MenuBar>
   </top>
</BorderPane>


您在FXML文件中的tableView没有和id,您有
,它应该像您在复选框、单选按钮等中那样分配id。

您能为我们添加一些代码吗?实际问题是什么?当我复制代码时,注释掉的行没有给出任何编译错误(尽管其他行也有,因为您依赖于未提供的类)。请解释观察到的和预期的行为是什么,并以@James\u D的形式提供代码。我只是用FXML添加了所有代码。再次,请解释实际问题是什么,并请编辑您的问题,使代码以@James\u D的形式出现。@James\u D,我现在取消注释尝试代码,它不会编译,我现在编辑主题,所以我使用场景生成器生成的控件创建控制器,它不是这样为我分配id:@FXML private CheckBox checkboxFeatureRhpsody;如果不是,我应该如何添加。谢谢大家!@在mainMrc.fxml文件中,使用:
而不是
谢谢这项工作,我对列做了相同的操作。问题是,我让它添加了两列,而不是使用我现有的一列,因此表中有4列而不是2列,@Win.ubuntu
<?xml version="1.0" encoding="UTF-8"?>

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

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.xcellcomm.Controller">
   <center>
      <VBox prefHeight="200.0" prefWidth="100.0" BorderPane.alignment="CENTER">
         <children>
            <Label text="Add New Activation :">
               <VBox.margin>
                  <Insets />
               </VBox.margin>
            </Label>
            <HBox prefHeight="100.0" prefWidth="200.0">
               <children>
                  <HBox prefHeight="90.0" prefWidth="200.0">
                     <children>
                        <VBox prefHeight="200.0" prefWidth="100.0">
                           <children>
                              <Label text="Select Plan Rate :" />
                              <RadioButton fx:id="plan40Radio" mnemonicParsing="false" text="40 or less Plan" />
                              <RadioButton fx:id="plan50Radio" mnemonicParsing="false" text="50 Plan" />
                              <RadioButton fx:id="plan60Radio" mnemonicParsing="false" text="60 Plan" />
                              <Region prefHeight="16.0" prefWidth="100.0" />
                              <Button fx:id="buttonAddActivation" mnemonicParsing="false" onAction="#buttonAddActivationPressed" text="Add Activation" />
                           </children>
                        </VBox>
                     </children>
                  </HBox>
                  <VBox prefHeight="102.0" prefWidth="163.0">
                     <children>
                        <Label text="Added Features :" />
                        <CheckBox fx:id="checkboxFeaturePhp" layoutX="10.0" layoutY="27.0" mnemonicParsing="false" text="PHP" />
                        <CheckBox fx:id="checkboxBlockIt" mnemonicParsing="false" text="Block it" />
                        <CheckBox fx:id="checkboxFeatureValueBundle" mnemonicParsing="false" text="Value Bundle" />
                     </children>
                  </VBox>
                  <VBox prefHeight="200.0" prefWidth="100.0">
                     <children>
                        <Label text="                           " />
                        <CheckBox fx:id="checkboxFeatureLookout" mnemonicParsing="false" text="Lookout MS" />
                        <CheckBox fx:id="checkboxFeatureRhpsody" mnemonicParsing="false" text="Rhapsody" />
                        <CheckBox fx:id="checkboxFeatureWorldCalling" mnemonicParsing="false" text="World Calling" />
                     </children>
                  </VBox>
               </children>
            </HBox>
            <Region prefHeight="23.0" prefWidth="600.0" />
            <HBox prefHeight="131.0" prefWidth="580.0">
               <children>
                  <TableView prefHeight="100.0" prefWidth="263.0">
                    <columns>
                      <TableColumn prefWidth="109.0" text="Time" />
                      <TableColumn prefWidth="82.0" text="Plan" />
                    </columns>
                     <HBox.margin>
                        <Insets left="10.0" />
                     </HBox.margin>
                  </TableView>
                  <Region prefHeight="200.0" prefWidth="200.0" HBox.hgrow="ALWAYS" />
                  <TableView prefHeight="100.0" prefWidth="309.0">
                    <columns>
                      <TableColumn prefWidth="147.0" text="Date" />
                      <TableColumn prefWidth="90.0" text="MRC" />
                    </columns>
                     <HBox.margin>
                        <Insets right="10.0" />
                     </HBox.margin>
                  </TableView>
               </children>
            </HBox>
            <Region prefHeight="29.0" prefWidth="580.0" />
            <HBox prefHeight="100.0" prefWidth="200.0">
               <children>
                  <VBox prefHeight="150.0" prefWidth="218.0">
                     <children>
                        <Label text="Today Activations" />
                        <TextField fx:id="textfeildTodayActivations" editable="false" maxWidth="100.0" prefHeight="39.0" prefWidth="100.0" promptText="Activations">
                           <font>
                              <Font size="18.0" />
                           </font>
                        </TextField>
                        <Label text="Today Goal" />
                        <TextField fx:id="textfeildTodayGoal" editable="false" maxWidth="100.0" prefHeight="39.0" prefWidth="100.0" promptText="Goal">
                           <font>
                              <Font size="18.0" />
                           </font>
                        </TextField>
                        <Label text="Current Process" />
                        <ProgressBar prefWidth="200.0" progress="0.0" />
                     </children>
                  </VBox>
                  <Region prefHeight="150.0" prefWidth="80.0" HBox.hgrow="ALWAYS" />
                  <LineChart prefHeight="150.0" prefWidth="281.0">
                    <xAxis>
                      <CategoryAxis side="BOTTOM" />
                    </xAxis>
                    <yAxis>
                      <NumberAxis side="LEFT" />
                    </yAxis>
                  </LineChart>
               </children>
            </HBox>
         </children>
         <BorderPane.margin>
            <Insets left="10.0" right="10.0" />
         </BorderPane.margin>
      </VBox>
   </center>
   <top>
      <MenuBar BorderPane.alignment="CENTER">
        <menus>
          <Menu mnemonicParsing="false" text="File">
            <items>
              <MenuItem mnemonicParsing="false" text="Close" />
            </items>
          </Menu>
          <Menu mnemonicParsing="false" text="Edit">
            <items>
              <MenuItem mnemonicParsing="false" text="Delete" />
            </items>
          </Menu>
          <Menu mnemonicParsing="false" text="Help">
            <items>
              <MenuItem mnemonicParsing="false" text="About" />
            </items>
          </Menu>
        </menus>
      </MenuBar>
   </top>
</BorderPane>