如何在NotSerializableException中标识匿名内部类 [英] How can I identify an anonymous inner class in a NotSerializableException

查看:275
本文介绍了如何在NotSerializableException中标识匿名内部类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在NetBeans中调试应用程序时收到以下错误消息:

I have received the following error message when trying to debug an application in NetBeans:


java.io.WriteAbortedException:write aborted; java.io.NotSerializableException:board.Board $ 1

java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: board.Board$1

在调试过程中,我不得不在一个数字中插入'implements Serializable'作为异常的类在从存储大对象的文件中读取的过程中出现。这并不困难,因为异常消息中已经清楚了需要注意的类。抛出我的是明显的匿名内部阶层'Board $ 1'。我不能为我的生活找出造成问题的董事会来源。我怎么能这样做?

In the course of debugging I have had to insert 'implements Serializable' in a number of classes as the exception arose in the course of reading from a file that stores a large object. This has not been difficult as the class needing attention has been clear from the exception message. What has thrown me is the apparent anonymous inner class 'Board$1'. I can't for the life of me identify the source with 'Board' that is causing the problem. How can I do this?

因为它是调试练习的问题而不是代码的细节(我认为)我没有包含它,但我可以轻松地如果它有帮助,请添加它。

As it's a question of debugging practice rather than the specifics of the code (I think) I haven't included it, but I can easily add that in if it helps.

推荐答案

Board $ 1 是第一个 Board.java 中遇到的匿名类。例如:

Board$1 is the first anonymous class encountered in Board.java. For example:

class Board {
  public static void main(String[] args) {
    new Object() {}; // Board$1
    new Object() {}; // Board$2
  }
}

使用像Eclipse这样的IDE,它是很容易在大纲视图中发现这些匿名类。我确信NetBeans有类似的观点:

With an IDE like Eclipse, it's easy to spot those anonymous classes in the outline view. I'm sure NetBeans has similar views:

这篇关于如何在NotSerializableException中标识匿名内部类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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