Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

keep getting InvalidClassException 1

Status
Not open for further replies.

frag

Programmer
Dec 7, 2000
321
GB
Hi!

I am trying to read a some kind of complex serialized object from a stream. Here is the object's class:

Code:
public class ReloadScheduleObj implements Serializable
{
  // *** object related varibles ***
  private String strSubimportKey;
  private String strSource;
  private String strCalculateAggs;
  private ReloadScheduleTableModel tmReloadSchedule;
  // *** gerneral varibles ***
  private int iReturnCode;
  private int a,x = 0;

 public ReloadScheduleObj()
 {
 	strSubimportKey = "";
 	strSource = "";
 	strCalculateAggs = "0";
 	tmReloadSchedule = null;
 	iReturnCode = -1;
 }


 // *** set and get methodes for object related variables ***
 public void setSubimportKey(String value){ strSubimportKey = value; }
 public String getSubimportKey(){ return strSubimportKey; }
 public void setSource(String value){ strSource = value; }
 public String getSource(){ return strSource; }
 public void setCalculateAggs(String value){ strCalculateAggs = value; }
 public String getCalculateAggs(){ return strCalculateAggs; }
 public void setReloadScheduleTableModel(ReloadScheduleTableModel value){ tmReloadSchedule = value; }
 public ReloadScheduleTableModel getReloadScheduleTableModel(){ return tmReloadSchedule; }
 public ReloadScheduleTableModel updateTableModel(ReloadScheduleTableModel tm){ }
 // *** set and get methodes for general variables ***
 public void setReturnCode(int value){ iReturnCode = value; }
 public int getReturnCode(){ return iReturnCode; }

}

While trying to read the object from the stream I get an InvalidClassException whenever I used the setReloadScheduleTableModel() methode before writing the object to the stream. The ReloadScheduleTableModel is a class that extends the DefaultTableModel. If I don't set the model at all then I can read the object. I can even read the object if I did something like setReloadScheduleTableModel(new ReloadScheduleTableModel()) but as soon as I set a object of ReloadScheduleTableModel that has been manipulated in any way before I will get the exception.

Here ist the exception:
Code:
java.io.InvalidClassException: javax.swing.JComponent; local class incompatible: stream classdesc serialVersionUID = -5353880800724033550, local class serialVersionUID = 5896976265092562486

We are talking about a client-server-application and I already tried to compile everything on the server-side and copy the class-files to the client but this didn't work. This was a tip I read in the SUN-forum.

I hope I explained my problem in a understandable way...

As always... any help is welcome.

Cheers

frag

patrick.metz@epost.de
 
Sounds like you cannot serialize one the dependant classes ...

From the API docs :

Thrown when the Serialization runtime detects one of the following problems with a Class.

The serial version of the class does not match that of the class descriptor read from the stream
The class contains unknown datatypes
The class does not have an accessible no-arg constructor
 
I read that too... but I did not understand it... ;-)

My guess is that it must have something to do with my tablemodel. But I don't know what... perhapse it is the checkbox (Boolean) in the model. I can't imagin where the JComponent in the exception comes from.

patrick.metz@epost.de
 
what about the class ReloadScheduleTableModel?

Is it serializable???
A serializable class must contain only Serializable elements.

ZePag
 
Yes it does, but perhapse I did something wrong??

Code:
public class ReloadScheduleTableModel extends DefaultTableModel implements Serializable

Is that ok or should it be:

Code:
public class ReloadScheduleTableModel implements Serializable extends DefaultTableModel


patrick.metz@epost.de
 
Give us the info ;)

What is there in your class????
Are all the attributes of this class (or inherent classes) serializable?

Let me look for a complete list of what is serializable and what is not.

moment please ;)
 
By the way Serializable only tags your class as one that can be serialized(??) ;)

It doesn't explicitly define how this class is serialized.
(you let the jvm handle it)

To explicitly do it, you have to implement Externalizable.

But that's not your point here.
 
I think you got all information about my classes.
This is the whole class definition for ReloadScheduleTableModel:

Code:
public class ReloadScheduleTableModel extends DefaultTableModel implements Serializable{
  

  public boolean isCellEditable(int row, int col) {
    if (col < 3) { 
        return false;
    } else {
        return true;
    }
  }
  

  public Class getColumnClass(int col) {
	if( col == 3 )
	 return Boolean.class;
	else
	 return String.class;
  }

}

patrick.metz@epost.de
 
One more time, check this recursively :)

Your class extends DefaultTableModel.
Is this other class Serializable?
 
Code:
public class ReloadScheduleTableModel extends DefaultTableModel implements Serializable

and

Code:
public class ReloadScheduleObj implements Serializable

As can be seen in my previous posts ;-)



patrick.metz@epost.de
 
In what you show me, I see 2 things :

You declare 2 classes as Serializable (means that YOU declare that every non-static or non-transient attribute of these classes is also Serializable)

This doesn't mean that they ARE serializable, but that YOU assume they are.

By the way,
public class ReloadScheduleTableModel extends DefaultTableModel implements Serializable
only means that:
- ReloadScheduleTableModel extends DefaultTableModel
- ReloadScheduleTableModel implements Serializable

But we don't know if DefaultTableModel implements Serializable or IS Serializable.

To sum up :
The important thing to understand is that implementing Serializable doesn't make a class Serializable.
You have to check it is by yourself by exploring wht it contains.

 
Ok, but how can I figure out if DefaultTableModel is Serializable? [neutral]

patrick.metz@epost.de
 
First clue : try to serialize it :) (half-joking)

Second Clue : go and see the javadoc to check its attributes.
 
Hm... so the API says DefaultTableModel implements Serializable. But I tried it without the &quot;implements Serializable&quot; for the ReloadScheduleTableModel and I keep getting the same exception. :-(

patrick.metz@epost.de
 
from the javadoc of DefaultTableModel :

Warning: serialized objects of this class will not be compatible with future swing releases. The current serialization support is appropriate for short term storage or RMI between Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.
 
I solved the problem... I am just not using the same java versions. On the server side there is running a java with version 1.4.2_02-b03 and on the client side there is 1.4.2-b28. If I run both the client and the server on the same machine the exception will not be thrown.

However this is not very useful. So I guess I will try to replace ReloadScheduleTableModel with a Vector that holds the needed information from ReloadScheduleTableModel.

I see no other possibility...

patrick.metz@epost.de
 
Or make a Custom class with just the Serializable elements you need from ReloadScheduleTableModel ;).

hope I helped anyway.

See you ;)
 
Yes you helped a lot. Especially you last post (with the warning) was very helpful and led me to the reason for the exception.

Thx :)

patrick.metz@epost.de
 
This is a stupid observation of mine but, should your code even have compiled?

public ReloadScheduleObj()
{
strSubimportKey = &quot;&quot;;
strSource = &quot;&quot;;
strCalculateAggs = &quot;0&quot;;
tmReloadSchedule = null;
iReturnCode = -1;
}

That method header is missing a return type. Like I said, a kinda stupid observation of mine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top