setcellValueFactory函数中的空指针异常

时间:2016-11-20 11:51:02

标签: java javafx

最近我遇到了问题,无法在互联网上找到任何解决方案。基本上我在javafx中填充表但是它抛出空指针异常。这是代码myCOntroller class

public class myController extends Stage implements Initializable {
    @FXML TableColumn<Information,char[]> Name;
    @FXML TableColumn<Information,String> Status;
    @FXML private TableView<Information> tableView = new TableView<Information>(); 
    private final ObservableList<Information> data =FXCollections.
                FXCollections.observableArrayList();
public void serverStart(ActionEvent event) throws IOException, InterruptedException{

        Parent root = FXMLLoader.load(getClass().getResource("/application/serverSecond.fxml"));
        Scene scene = new Scene(root);
        scene.getStylesheets().add(getClass().getResource("/application/application.css").toExternalForm());
        this.setScene(scene);
        this.show();
        tcpserver server=new tcpserver(8088);
        Task<Void> t=new Task<Void>() {

            @Override
            protected Void call() throws Exception {
                // TODO Auto-generated method stub
                server.start();
                return null;
            }
        };
        new Thread(t).start();
        data.add(server.I);
        System.out.println(data.get(0).Name);
        tableView.setItems(data);
    }

这是我的serverSecond.fxml文件

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

<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="461.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Controller.myController1">
   <children>
      <TableView fx:id="tableView" layoutX="73.0" layoutY="112.0" prefHeight="271.0" prefWidth="392.0">
        <columns>
          <TableColumn fx:id="Name" prefWidth="222.0" text="Name" />
          <TableColumn fx:id="Status" minWidth="0.0" prefWidth="169.0" text="Status" />
        </columns>
      </TableView>
      <Label alignment="CENTER" layoutX="210.0" layoutY="41.0" prefHeight="39.0" prefWidth="173.0" text="Teacher">
         <font>
            <Font size="20.0" />
         </font>
      </Label>
   </children>
</AnchorPane>

这是我的information.java文件

package application;



public class Information {
    public char[] Name;
    public String Status;
    public char[] getName() 
    {
            return Name;
    }
    public void setName(char[] Name) {
            this.Name=Name;
     }
    public char[] getStatus() 
    {
            return Name;
    }

    public void setStatus(String Status) {
            this.Status=Status;
     } 
}

0 个答案:

没有答案