读取序列化对象时出现错误(java.io.StreamCorruptedException:无效类型代码:00)。这是实现可序列化的类:
package guts;
import cc.mallet.classify.*;
import java.io.*;
public class NaiveBayesWithID implements Serializable {
private NaiveBayes nb;
private static final long serialVersionUID = 1;
private static final int CURRENT_SERIAL_VERSION = 1;
public NaiveBayesWithID(NaiveBayes nb) {
this.nb = nb;
}
public NaiveBayesWithID(){
this.nb = null;
}
public void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
int version = in.readInt();
if (version != CURRENT_SERIAL_VERSION)
throw new ClassNotFoundException("Mismatched NaiveBayesTrainer versions: wanted " +
CURRENT_SERIAL_VERSION + ", got " +
version);
//default selections for the kind of Estimator used
NaiveBayesWithID test = (NaiveBayesWithID) in.readObject();
// nb = test.returnNB();
}
public void writeObject(ObjectOutputStream out) throws IOException
{
out.writeInt(CURRENT_SERIAL_VERSION);
//default selections for the kind of Estimator used
out.writeObject(this);
}
public NaiveBayes returnNB(){
return nb;
}
public void setNB(NaiveBayes nb){
this.nb = nb;
}
}
这是堆栈跟踪:
java.io.StreamCorruptedException: invalid type code: 00
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1355)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
at java.util.ArrayList.readObject(ArrayList.java:593)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1848)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
at cc.mallet.pipe.SerialPipes.readObject(SerialPipes.java:142)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1848)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
at guts.NaiveBayesWithID.readObject(NaiveBayesWithID.java:29)
at controllers.Application.predict(Application.java:481)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:408)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:403)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:176)
at play.server.PlayHandler$NettyInvocation.execute(PlayHandler.java:169)
at play.Invoker$Invocation.run(Invoker.java:187)
at play.server.PlayHandler$NettyInvocation.run(PlayHandler.java:149)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
有谁知道我如何获得有关该错误的更多信息?还是Java期望哪个对象?
您已经实现了一种递归writeObject
方法:将实例写入输出流时,它会调用writeObject方法,该方法将写入一个int,然后将该对象写入输出流,再写入一个int,依此类推。
serialVersionUID字段的目标是检查对象是否兼容。它是由序列化机制本地完成的。除了在类更改时更改serialVersionUID值外,您无需执行任何其他操作。
问题内容: 我的问题是,当它尝试第二次读取对象时,会引发异常: 我第一次发送完全相同的对象消息;但是,当我第二次尝试执行相同的操作时,则会在上面抛出错误。我是否需要重新初始化readObject()方法?我什至打印出了下面一行所接收到的消息对象,它与第一个可以正常工作的实例完全相同。 Object buf = myInput.readObject(); 我假设附加有一些问题,但是附加确实没有用。我
我试图发送对象从服务器模块到客户端模块。不幸的是,它抛出错误。有人知道下面的代码有什么问题吗? 来自服务器模块的类 客户端模块中的类看起来相同,但看起来如下所示: 最后一个类,它接受套接字连接:
我正在尝试开发一个Java客户机-服务器应用程序,其中多个客户机可以连接到服务器。我为每个传入的客户机启动一个单独的线程,将客户机套接字传递给该线程,然后打开一对流来维护通信。我得到了这个java。伊奥。StreamCorruptedException-无效的代码类型AC。 根据我的研究,这意味着我使用一个新的ObjectOutputStream来写入现有的ObjectInputStream。然而
我有一门课是这样的: 但是当我试图序列化它时,我收到一个错误,上面写着“试图序列化java.lang.class:java.lang.字符串。忘记注册一个类型适配器了吗?”。所以我创建了这个适配器: } 并登记如下: 但我还是犯了同样的错误<我做错了什么 适配器的实现看起来正常吗?
问题内容: Eclipse JDT编译器似乎存在一个问题,在某些情况下,Java 8 lamda不能正确反序列化,而是抛出。我正在使用最新发布的维护版本,如下所示: 现有的Bug / SO条目报告了已(至少部分地)已解决的类似问题。我已经亲自验证以下问题已解决。 访问实例字段和方法的Java 8Lambda不能反序列化 https://bugs.eclipse.org/bugs/show_bug.
Eclipse JDT编译器似乎有一个问题,在某些情况下,Java8个lamda没有正确反序列化,而是抛出一个。我正在使用最近的分布式维护版本,如下所示: 现有的bug/SO条目报告了在中已经(至少部分)解决的类似问题。我亲自验证了以下问题已经得到解决。 无法反序列化访问实例字段和方法的Java 8 lambda https://bugs.eclipse.org/bugs/show_bug.cgi