带有"$ 1"的java.io.NotSerializableException;下课以后 [英] java.io.NotSerializableException with "$1" after class

查看:55
本文介绍了带有"$ 1"的java.io.NotSerializableException;下课以后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到序列化问题,无法找到原因.这是Eclipse中的Android应用程序,它给了我一个非常无用的堆栈跟踪,如下所示:

I have a serialization problem and am unable to find the cause. It's an Android app in Eclipse that's giving me a very unhelpful stack trace like this:

09-01 00:06:24.414: W/System.err(9961): java.io.NotSerializableException: com.myprogram.main.Entity$1
09-01 00:06:24.414: W/System.err(9961):     at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1344)
09-01 00:06:24.414: W/System.err(9961):     at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
09-01 00:06:24.414: W/System.err(9961):     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
09-01 00:06:24.414: W/System.err(9961):     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
09-01 00:06:24.415: W/System.err(9961):     at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:959)
09-01 00:06:24.415: W/System.err(9961):     at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:360)
09-01 00:06:24.415: W/System.err(9961):     at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1054)
09-01 00:06:24.415: W/System.err(9961):     at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1384)
09-01 00:06:24.415: W/System.err(9961):     at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
09-01 00:06:24.415: W/System.err(9961):     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
09-01 00:06:24.415: W/System.err(9961):     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)

找到了用于启用扩展序列化调试信息的Java标志我决定设置

-Dsun.io.serialization.extendedDebugInfo=true

遵循如何为从eclipse运行的程序指定默认的JVM参数?将标志插入VM我的JRE的参数,但堆栈跟踪没有更改.重新启动Eclipse并没有帮助.因此,在编辑eclipse的vm args 之后,我将该标志添加到了eclipse.ini中,但是堆栈跟踪仍然保持不变.我期望输出看起来像

Following How can I specify the default JVM arguments for programs I run from eclipse? I plugged the flag into the VM argument for my JRE, but the stack trace did not change. Rebooting Eclipse did not help. So following Editing the vm args of eclipse I added the flag to my eclipse.ini, but still the stack trace is unchanged. I'm expecting an output that looks something like java.io.NotSerializableException – but where is the field?.

我发现 com.myprogram.main.Entity $ 1 无法序列化.这很容易.问题是为什么?关于如何解决此 java.io.NotSerializableException 的任何建议?

I get it that com.myprogram.main.Entity$1 is not serializable. That's easy. The question is why? Any suggestions as to how I might figure out this java.io.NotSerializableException?

推荐答案

您有一个匿名内部类 com.myprogram.main.Entity $ 1 ,它不能进行可序列化.例外情况清楚地说明了这一点. $ 表示它是产生异常的内部或静态嵌套类. $ 之后的数字表示该类是匿名的,否则内部类的名称将出现在此处. 1 进一步指示这是 com.myprogram.main.Entity 中的第一个匿名内部类.

You have an anonymous inner class com.myprogram.main.Entity$1 that isn't Serializable. This is clearly stated in the exception. The $ indicates that it's an inner or static nested class that produced the exception. The digit after the $ indicates that the class is anonymous, otherwise the name of the inner class would be present here. The 1 further indicates that this is the first anonymous inner class within com.myprogram.main.Entity.

有关更多信息,请参见如何在NotSerializableException中识别匿名内部类.

See How can I identify an anonymous inner class in a NotSerializableException for more.

这篇关于带有"$ 1"的java.io.NotSerializableException;下课以后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆