I am trying to implement this example in Java FX 11 with eclipse.

I have 4 files, FXMLTableView.java hast the start and main method, FXMLTableViewController.java(which is just empty with class declaration only, fxml_tableview.fxml has the fxml code. Person.java has the Person class as shown in the above link. I am getting error which when I remove this code (I am using only one line for testing) from fxml the program runs but ofcourse there is no data in the column:

<Person firstName="Jacob" lastName="Smith"email="[email protected]"/>

Any suggestions how to solve this problem?

Below is the error code:

Exception in Application start method
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: javafx.fxml.LoadException: 
/C:/Users/Air/eclipse-workspace/FXMLTableView/bin/table/view/fxml_tableview.fxml:41

    at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2568)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3237)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3194)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3163)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3136)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3113)
    at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3106)
    at table.view.FXMLTableView.start(FXMLTableView.java:13)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    ... 1 more
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[41,53]
Message: Element type "Person" must be followed by either attribute specifications, ">" or "/>".
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:652)
    at java.xml/javax.xml.stream.util.StreamReaderDelegate.next(StreamReaderDelegate.java:84)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2538)
    ... 17 more
Exception running application table.view.FXMLTableView

Code in FXML file:

<?import javafx.scene.layout.GridPane?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.cell.*?> 
<?import javafx.scene.control.*?> 
<?import javafx.collections.*?> 
<?import javafx.fxmltableview.*?> 
<?import javafx.beans.property.SimpleStringProperty?>

<GridPane alignment="CENTER" hgap="10.0" vgap="10.0" xmlns:fx="http://javafx.com/fxml">
    <padding>
        <Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
    </padding>
    <Label style="-fx-font: NORMAL 20 Tahoma;" text="Address Book"                
        GridPane.columnIndex="0" GridPane.rowIndex="0">
    </Label>
    <TableView  GridPane.columnIndex="0" GridPane.rowIndex="1">
         <columns> 
            <TableColumn text="First Name">
                <cellValueFactory><PropertyValueFactory property="firstName" />
                </cellValueFactory>
            </TableColumn>

             <TableColumn text="Last Name">
                <cellValueFactory><PropertyValueFactory property="lastName" />
                </cellValueFactory>
             </TableColumn>

             <TableColumn text="Email Address">
                 <cellValueFactory><PropertyValueFactory property="email" />
                 </cellValueFactory>
            </TableColumn>
         </columns>  

         <items>
            <FXCollections fx:factory="observableArrayList">
                <Person firstName="Jacob" lastName="Smith"email="[email protected]"/>

            </FXCollections>
        </items>
    </TableView>


</GridPane>

0 Answers