Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
295 views
in Technique[技术] by (71.8m points)

java - How can I identify an anonymous inner class in a NotSerializableException

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

java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: board.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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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
  }
}

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

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...