[英]how to fix serialVersionUID not equal exception in the same class?
java.io.InvalidClassException:
com.sungymobile.cache.resource.ResourceCacheLoader$ResourceCache;
local class incompatible: stream classdesc serialVersionUID = 6381106003702990139,
local class serialVersionUID = 3777451853403693248
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:
由于Java文档可序列化界面:
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.
序列化运行时与每个可序列化的类关联一个版本号,称为serialVersionUID,在反序列化期间使用该版本号来验证序列化对象的发送者和接收者是否已加载了该对象的与序列化兼容的类。 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.
如果接收方已为该对象加载了一个与相应发送方类具有不同的serialVersionUID的类,则反序列化将导致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:
可序列化的类可以通过声明一个名称为“ serialVersionUID”的字段来显式声明其自己的serialVersionUID,该字段必须是静态的,最终的且类型为long:
This value is needed to determine, wether cached instance is the same version with the current class, you have. 需要使用此值来确定您所缓存的实例与当前类的版本是否相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.