This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Why would my TableView getItems() and Clear() be failing when other TableViews work without issue?  RSS feed

 
Ranch Hand
Posts: 54
2
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My problem:
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:
 
Marshal
Posts: 5995
156
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you show us how tblSearchFiles and tblSources are declared and how tblSources is initialized?  It looks like you have one item in tblSearchFiles of type Notebook.  Can we see that class?
 
Scott Vallery
Ranch Hand
Posts: 54
2
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, np - anything that may help!

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
Marshal
Posts: 5995
156
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Scott Vallery
Ranch Hand
Posts: 54
2
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Scott Vallery
Ranch Hand
Posts: 54
2
Eclipse IDE IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SOLVED!!!

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.
 
Knute Snortum
Marshal
Posts: 5995
156
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great job figuring it out and posting back here!

My take on why getItems().addAll(...) works better that setItems() is because the latter can take an unmodifiable List.  Then clear() fails.

So always use getItems().addAll(...).
 
Let nothing stop you! Not even this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!