0

Recently I got stuck in a problem and unable to find any solution on internet.Basically i am populating the table in javafx but it throws null pointer exception.Here is the code 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);
    }

this is my serverSecond.fxml file

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

and this is my information.java file

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;
     } 
}
  • 1
    Why don't you post the exception? – Frank Puffer Nov 20 '16 at 11:54
  • 1
    Welcome to Stack Overflow! It looks like you need to learn to use a debugger. Please help yourself to some [complementary debugging techniques](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/). If you still have issues afterwards, please feel free to come back with more details. – Joe C Nov 20 '16 at 12:27

0 Answers0