Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.io.NotSerializableException when overwrite the JTable data into .txt file

 
roger lim shau xiong
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everyone

i had java.io.NotSerializableException: java.lang.reflect.Constructor error when overwrite the JTable data into .txt file.
At the beginning, the code will be generate successfully and the jtable will be showing out with the data that been save in the studio1.txt previously,
but after i edit the data at the JTable, and when i trying to click the save button, the error had been showing out and i cannot succeed to save the JTable with the latest data.
After this error, the code can't be run again and i had to copy the studio1.txt again to let the code run 1 more time.
I hope i can get any solution at here and this will be very useful for me.
but i dunno how to attach my .txt file with this forum
did anyone need the .txt file?

i had edit the code and make it simple for reading
this is the objectinput code



this is the objectoutput code

 
Campbell Ritchie
Sheriff
Posts: 51447
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

Please show us which line the Exception occurred on. Don't know whether the text file is necessary or not. Sorry.

You will need to find every object which might be invoked on that line, and check whether it is null, which is that much more difficult with all the additional code from NetBeans.
 
roger lim shau xiong
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, thank you for reply me
i cant find the line of the exception code.


i had /*...*/ some of the code that generate from the GUI netbean at following

 
Bert Bates
author
Sheriff
Posts: 8905
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
intermediate level question
 
roger lim shau xiong
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
did anyone know how to attach the .txt file?
 
Campbell Ritchie
Sheriff
Posts: 51447
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bert Bates wrote:intermediate level question
It wasn't originally. It was about finding a NullPointerException.

roger lim shau xiong:Why have you changed the original posting? It was about NullPointerExceptions yesterday, not NotSerializableExceptions. Why are you quoting different code from yesterday? If you change the original posting the replies will turn to nonsense.

Why are you passing so many nulls? Are you initialising all those references to real objects?
 
roger lim shau xiong
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i had changed it because i had update the latest coding
i had change the code which i had show at the first msg
and i had change the subject because i found that the first line of the exception should be the java.io.NotSerializableException
and nullpointer exception had show at the bottom of NotSerializableException
and sorry for this, i won't change the original posting next time

the nulls is only the object that created by netbean
i had try to fill it full with object but the problem still the same
sorry again for the unconvenient
 
roger lim shau xiong
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i had found a new thing that when i just double click the cell without change any data inside the table
and click the button "Save". the same exception which is
java.io.NotSerializableException: java.lang.reflect.Constructor
will come out again.
 
Campbell Ritchie
Sheriff
Posts: 51447
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you serialize an object, every field of every class must be a primitive or implement the Serializable interface or be labelled transient. So go through all your classes and look at all their types and see whether they all implement Serializable. Many well-known classes, eg String, ArrayList, already implement Serializable, so look at all the other classes.
 
roger lim shau xiong
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i had create another class to serialize it



and the outputstream i change to this


After this i click the save button
the java.io.NotSerializableException had been solve
but when i trying to read back the studio1.txt
it comes out another exception
Problem reading back table from file: studio1.txtjava.lang.ClassCastException: gui.Data
 
roger lim shau xiong
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my problem had been solve since i create this class


but there is another problem after i save the table
after i save the table, i click the load button to load back,
the table just become empty ,its looks like load a empty object into the frame
can anybody help me with this problem?

i can save the JTable by this code


and i load the JTable by this code


after this my table become empty..just like a empty frame.
anybody help will be my very appreciate
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic