似乎我无法序列化我的名为“Ban”的课程:
class Ban implements Serializable{
/**
*
*/
transient Date start;
transient Date end;
String explination;
String from;
public Ban(Date s, Date e, String ex, String f){
start = s;
end = e;
explination = ex;
from = f;
}
}
当我尝试用 objectoutputstream 打印它时,它给了我一个错误......你能帮我序列化这个类吗?顺便说一句:瞬态是什么意思?
好吧,它是 bukkit,但应该这样做:
[SEVERE] java.io.NotSerializableException: me.bubblegumsoldier.Ban.Main
2013-04-03 19:30:30 [SEVERE] at java.io.ObjectOutputStream.writeObject0(Unknown Source)
2013-04-03 19:30:30 [SEVERE] at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
2013-04-03 19:30:30 [SEVERE] at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
2013-04-03 19:30:30 [SEVERE] at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
2013-04-03 19:30:30 [SEVERE] at java.io.ObjectOutputStream.writeObject0(Unknown Source)
2013-04-03 19:30:30 [SEVERE] at java.io.ObjectOutputStream.writeObject(Unknown Source)
2013-04-03 19:30:30 [SEVERE] at java.util.HashMap.writeObject(Unknown Source)
2013-04-03 19:30:30 [SEVERE] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2013-04-03 19:30:30 [SEVERE] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
2013-04-03 19:30:30 [SEVERE] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
2013-04-03 19:30:30 [SEVERE] at java.lang.reflect.Method.invoke(Unknown Source)
2013-04-03 19:30:30 [SEVERE] at java.io.ObjectStreamClass.invokeWriteObject(Unknown Source)
2013-04-03 19:30:30 [SEVERE] at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
2013-04-03 19:30:30 [SEVERE] at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
2013-04-03 19:30:30 [SEVERE] at java.io.ObjectOutputStream.writeObject0(Unknown Source)
2013-04-03 19:30:30 [SEVERE] at java.io.ObjectOutputStream.writeObject(Unknown Source)
2013-04-03 19:30:30 [SEVERE] at me.bubblegumsoldier.Ban.Main.save(Main.java:113)
2013-04-03 19:30:30 [SEVERE] at me.bubblegumsoldier.Ban.Main.onDisable(Main.java:247)
2013-04-03 19:30:30 [SEVERE] at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:219)
2013-04-03 19:30:30 [SEVERE] at org.bukkit.plugin.java.JavaPluginLoader.disablePlugin(JavaPluginLoader.java:481)
2013-04-03 19:30:30 [SEVERE] at org.bukkit.plugin.SimplePluginManager.disablePlugin(SimplePluginManager.java:400)
2013-04-03 19:30:30 [SEVERE] at org.bukkit.plugin.SimplePluginManager.disablePlugins(SimplePluginManager.java:393)
2013-04-03 19:30:30 [SEVERE] at org.bukkit.craftbukkit.v1_5_R2.CraftServer.disablePlugins(CraftServer.java:277)
2013-04-03 19:30:30 [SEVERE] at net.minecraft.server.v1_5_R2.MinecraftServer.stop(MinecraftServer.java:331)
2013-04-03 19:30:30 [SEVERE] at net.minecraft.server.v1_5_R2.MinecraftServer.run(MinecraftServer.java:438)
2013-04-03 19:30:30 [SEVERE] at net.minecraft.server.v1_5_R2.ThreadServerApplication.run(SourceFile:573)
我的保存代码如下所示:
变量:
public static HashMap<String, Ban> banned = new HashMap<String, Ban>();
节省部分:
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
oos.writeObject(banned);
oos.flush();
oos.close();