Closed N00ree closed 2 years ago
Not a FlatLaf Issue. The exception is still thrown even without using FlatLaf at all... Sorry about that, have a great weekend all.
Ok, actually it is a FlatLaf Issue. I couldn't get the hang of it at first and couldn't provide a specific reproducible example but now I have it.
I updated the issue with the current reproducible example (Stack Trace also updated) I added a 1-second sleep before serialization, which helps to resolve the initial Nullpointer. I am also creating the UI on the EDT, which is better.
I don't know the technical background of it, but I think the GUI must be ready before serializing stuff, that's why I added the delay before serializing.
After all this, FlatLaf is causing an additional NullPointer. See the updated example/stacktrace above.
I hope someone can help. Any tips are appreciated.
This is a threading issue.
You should not serialize Swing objects on the main thread. Always do it on the AWT thread. Then it works.
But this also serializes the JTable
(and maybe the complete component hierarchy)
because the table adds a listener to the model. So there is a reference from the model to the table...
I would avoid serialization of table model. Better serialize a custom object.
Hi there, thanks for the fast reply. Because I am generally an impatient person, I also asked a question on Stackoverflow and also got help from there.
I first thought that a TableModel is more like a model than a Swing Component, but I was wrong. There is (somehow) a connection to the JTable that causes it - as you described above.
Also the Javadoc about AbstractTableModel doesn't recommend serializing it. Maybe this is interesting too.
Even though I only know about the EDT (Event Dispatcher Thread), the AWT thread is probably another naming for it - right?
Simple conclusion for this issue - Putting the TableModel initialization and the serializing code inside the EDT fixes it.
Thank you again and have a great day.
Even though I only know about the EDT (Event Dispatcher Thread), the AWT thread is probably another naming for it - right?
yes
Hi,
a NullPointerException is thrown when trying to serialize a TableModel object while the associated JTable object is visible in a JFrame. I created a minimal, reproducible Example and will also include the Stack-Trace.
I hope someone can help. I am using AdoptOpenJDK14 (14.0.2.12-hotspot)
Here is the minimal, reproducible Example:
Serialization.java (Entrypoint of the Program)
MyAbstractModel.java (The Model to Serialize)
This is the Stacktrace I got.