java.io.NotSerializableException:无法理解我为什么得到这个?

时间:2018-07-16 12:59:30

标签: arrays object error-handling deserialization file-handling

我正在使用序列化将对象数组保存在文件中,但这给我一个错误。 dataToSave是我要保存的对象的数组。

 public void saveFile(){

      try{
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("serial"));
            oos.writeObject(dataToSave);
            oos.close();
            System.out.println("Done");
      }
        catch (Exception e) {
          e.printStackTrace();

        }
    }




 public class NeuralNetwork implements Serializable{

      int input=27,hiddenLength=16,hidden[],output=4;
      double inputMatrix[];                            //INPUT MATRIX
      public double weightOne[][];                             // WEIGHT FROM INPUT TO HIDDEN
      double hiddenMatrix[];                          //hidden values
      public double weightTwo[][];                              //  WEIGHT FROM HIDDEN TO OUTPUT
      double outputMatrix[];

..... 
.....
}
  

java.io.NotSerializableException:蛇机游戏位于   java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)     在   java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)     在   java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)     在   java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)     在   java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)     在   java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1378)     在   java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)     在   java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)     在snake_game.saveFile(snake_game.java:113)处   snake_game.keyPressed(snake_game.java:101)在   processing.core.PApplet.keyPressed(PApplet.java:3053)位于   processing.core.PApplet.handleKeyEvent(PApplet.java:2928)在   processing.core.PApplet.dequeueEvents(PApplet.java:2599)位于   processing.core.PApplet.handleDraw(PApplet.java:2437)在   processing.awt.PSurfaceAWT $ 12.callDraw(PSurfaceAWT.java:1557)在   processing.core.PSurfaceNone $ AnimationThread.run(PSurfaceNone.java:316)

0 个答案:

没有答案