java.io.NotSerializableException: LogModel錯誤

  try{
            oout=new ObjectOutputStream(
                    new BufferedOutputStream(
                            new FileOutputStream(f)
                    )
            );
            oout.writeObject(list);//
        }catch (Exception e){
            e.printStackTrace();
        }


//部分報錯:java.io.NotSerializableException: LogModel

所以去看這個方法對應的註解:

     * @throws  InvalidClassException Something is wrong with a class used by
     *          serialization.
     * @throws  NotSerializableException Some object to be serialized does not//
     *          implement the java.io.Serializable interface.
     * @throws  IOException Any exception thrown by the underlying
     *          OutputStream.
     */
    public final void writeObject(Object obj) throws IOException 

對應//是//的錯誤,所以得到解決辦法:如下,list對應的對象要實現serializable的接口。


public class LogModel implements Serializable {
}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章