找到你要的答案

Q:how to fix serialVersionUID not equal exception in the same class?

Q:如何解决不平等的serialVersionUID例外在同一个班吗?

java.io.InvalidClassException:
com.sungymobile.cache.resource.ResourceCacheLoader$ResourceCache; 
local class incompatible: stream classdesc serialVersionUID = 6381106003702990139, 
local class serialVersionUID = 3777451853403693248
java.io.InvalidClassException:
com.sungymobile.cache.resource.ResourceCacheLoader$ResourceCache; 
local class incompatible: stream classdesc serialVersionUID = 6381106003702990139, 
local class serialVersionUID = 3777451853403693248
answer1: 回答1:

Seems, that you have a serialized class, that does not provide fixed serial version parameter. You have to provide:

private static final long serialVersionUID = 0L;

With any long value in your class, which must to be cached. Due to Java Docs for Serializable interface:

The serialization runtime associates with each serializable class a version number, called a serialVersionUID, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization. If the receiver has loaded a class for the object that has a different serialVersionUID than that of the corresponding sender's class, then deserialization will result in an InvalidClassException. A serializable class can declare its own serialVersionUID explicitly by declaring a field named "serialVersionUID" that must be static, final, and of type long:

This value is needed to determine, wether cached instance is the same version with the current class, you have.

看来,你有一个序列化类,不提供固定的串行版本参数。你必须提供:

private static final long serialVersionUID = 0L;

类中的任何长值,必须缓存它们。由于串行化接口的java文件:

每个可序列化的类的版本号的序列化运行时的同事,被称为一个serialVersionUID,用于在反序列化期间验证发送方和接收器有序列化对象,对象是相对于序列化兼容加载的类。如果接收机,具有比相应的类的对象发送不同的serialVersionUID加载一个类,然后反序列化将导致invalidclassexception。一个可序列化的类可以声明自己明确声明serialVersionUID字段命名为“serialVersionUID”必须是静态的,最终的,和长型:

这个值是需要确定是否缓存实例与当前类的相同的版本,你有。

java  serialversionuid