PlayList類和Song類都已經繼承了序列化接口?。????public class PlayList implements Serializable????public class Song implements Serializable主程序中的代碼:case 8: System.out.println("導出歌單 "); System.out.println("請輸入要導出的歌曲列表名稱: "); instr = scanner.next(); String fileName = instr + "的歌單.txt"; if (playListCollection.searchPlayListByName(instr) != null) { PlayList sPlayList = playListCollection.searchPlayListByName(instr); try { FileOutputStream fos = new FileOutputStream(fileName); ObjectOutputStream oos = new ObjectOutputStream(fos); FileInputStream fis = new FileInputStream(fileName); ObjectInputStream ois = new ObjectInputStream(fis); // 寫入對象// oos.writeObject(sPlayList); Iterator<Song> it = sPlayList.getMusicList().iterator(); while (it.hasNext()) { oos.writeObject(it.next()); } oos.flush(); // 讀對象信息 try { PlayList rPlayList = (PlayList) ois.readObject(); System.out.println(rPlayList); } catch (ClassNotFoundException e) { e.printStackTrace(); } oos.close(); fos.close(); ois.close(); fis.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } PlayListMenu(); break;
為什么會一直提示java.io.NotSerializableException: imooc.playlist.PlayList錯誤呢?
沫沫Michelle
2017-09-13 17:12:19