Much like this question, I am trying to update a TableView in JavaFX. I have adopted the solution using DataFX.

My code :

File file = new File(path);
if(file.exists() && file.canRead()) {
    DataSourceReader dsr1 = new FileSource(file);
    String[] columnsArray = {"firstName", "lastName"}; 
    CSVDataSource ds1 = new CSVDataSource(dsr1, columnsArray);
    System.out.println("CSV : " + ds1.getData().size());  // outputs 0

    //Below is commented out since I don't have data : source of the error
    //tblAthleteList.setItems(ds1.getData());
    //tblAthleteList.getColumns().addAll(ds1.getColumns());
}

Here is a view of my test .csv file :

firstName, lastName
first, last
test, tester

I am using JavaFX 2, DataFX 1.0 and building in e(fx)clipse

Edit

Have changed the code a bit to use the FileSource(File f) constructor to see if this changes anything. Turns out I am trying to print something from the CSVDataSource and I always get a NullPointerException. Therefore assumming that the CSVDataSource doesn't get any data. From examples I can find this is being done correctly. I can read the file using a simple BufferedReader and a loop.

Edit 2

Edited the question... I am now specifying that the error is in the fact that no data gets pulled into the CSVDataSource from the .csv file. The line ds1.getData().size() returns 0. Posted a very simple .csv file I am using. EOL consists of CR + LF and edited in Notepad++ (no Excel superfluous characters).

有帮助吗?

解决方案

make sure column names in columnsArray are exactly equal to column names in CSV file (case sensitive).

i got the similar exception when i put my column name as year in code but in my csv file its Year.

Update According to Edit in Question :

remove space between , and lastName in file or put " lastName" as column name in code :)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top