When attempting to add or clear data into a JavaFX TableView, I receive "java.lang.UnsupportedOperationException" but I can setItems() on loading.
This is the fourth of 4 such tables with the same identical functionality just different string data, which either 1) adds data to fields, 2) removes data from fields, or 3) clears data from fields. Though I'm not certain I agree, in searching for a resolution surrounding the errors, many post referenced to the initialization of the FXMLLoader. It didn't make sense but I tried that in 2 different ways suggested but neither initialization made a difference in impact. So I'm stuck. I have double checked that I haven't mistakenly referred to the wrong tables etc.
The table is based upon the type class "NoteFile" which amounts to 2 SimpleStringProperties FileName and FilePath. These are retrieve through the FileAttachmentManager which will later use that data to convert the file to bytes for database storage. But we aren't that far yet. This issue is just adding or clearing NoteFile string data from the tableview.
The error on line 4 referencing back to line 1302 refers to line 12 in the code below. The same error occurs on the call on line 18 below but not line 17:
I included tblSources as requested but also the tblFiles (TableView) because it performs the same identical functions as I need for the tblSearchFiles just on a different tab of the GUI and yet has no issues with add, remove or clear. I would like to add that while stepping through the FXMLLoader method invocation.. the error is a InvocationTargetException but returns as UnsupportedOperationException - not sure if that may be significant.
// Performed at application initialization
// The NoteFile class which is the type class referenced in the declarations for tblFiles and tblSearchFiles
Knute Snortum wrote:Thanks. Nothing unusual that I can see.
Is there any possibility that tblSearchFiles calls setItems() at some point? Are you only doing add()s? Is there a difference between how tblSearchFiles and tblFiles are getting data?
Is there any possibility that tblSearchFiles calls setItems() at some point? Yes, table could be populated using setItems() if file attachments are available - otherwise setItems() never occurs.
This table is located on a review tab for a database entries. So the functionality for this tab "searches" a particular database entry the user selects. This database entry may or may not have attached files to reference. If this database entry has a file(s) attached, then they will be called by the "setItems()" and populated. However, the user may want to remove one of those files, or add (attach) a new file.
Another scenario is that a database entry may not have any file attachments at all during review, but the user may want to add a file.
Are you only doing add()s? No, there would also need to be remove or clear capability.
Is there a difference between how tblSearchFiles and tblFiles are getting data? A little trickier... I would say No. They both use the same functionality to add, remove, or clear data from the table. The exception is that tblFiles is never using setItems(). Data is read from this table and entered as part of a new database entry, whereas, tblSearchFile shoud be able to do the same AND is also populated with existing file attachment string data from the database.
Well Knute, rather than editing my post I thought I would keep the solution separate from my previous posting answering your questions. So the change I made was using getItems() vs setItems() (see below). For those in the future, maybe you will want to explain why using setItems() vs. getItems() makes a difference.
I can't say I understand why this makes a difference, I would have never suspected it.
Thanks for helping me think it through!
The 'search.Count' will count the number of records for a particular Table/Field/Criterion combination. In this case if the count is >0, then I use tblSearchFiles.getItems() vs setItems() and it resolved my problem. The code commented out was being used before.