0

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="jacob.smith@example.com"/>

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="jacob.smith@example.com"/>

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


</GridPane>
Ali
  • 479
  • 4
  • 11
  • That example works fine for me with JavaFX 11. Edit your question and post the full stacktrace. – José Pereda May 03 '19 at 12:59
  • I added the error, what do you mean by stack trace? – Ali May 03 '19 at 13:06
  • This message `Person.person is not a valid property` in your "[stacktrace](https://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors)" indicates that your project doesn't find `Person` in the `fxmltableview` package. – José Pereda May 03 '19 at 13:07
  • Also it shows you are using a new package name: `table.view`, which is okay, of course, but you will need to do some refactoring as well in the FXML file. – José Pereda May 03 '19 at 13:10
  • I made a change Person.person to person, so the error code also changed. Also I included the fxml code. – Ali May 03 '19 at 13:22
  • What is this import ` `? The original code was at the package `fxmltableview`, but yours is `table.view`, just use the correct import. – José Pereda May 03 '19 at 13:40
  • don't have much idea, I copied a bunch of imports from here and there to get the code running, initially i wasn't getting any output, I changed it to import javafx.table.view.*?> now, but still getting the error. – Ali May 03 '19 at 13:46
  • I copied the whole code again now it's working, i think it's cause i didnt' include FormattedTableCellFactory.java the first time when I run the program.@Jose thank you for your support. specially the bit about fxmltableview I didn't notice that at all. – Ali May 03 '19 at 14:09
  • Still that is wrong, the import should include your package name, with your classes, not one that doesn’t exist. – José Pereda May 03 '19 at 14:11
  • sorry , I got that, thanks. – Ali May 03 '19 at 14:13

0 Answers0