错误:
java.lang.ClassNotFoundException: testprocedure.tp$3 at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java .net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java .lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at java.io.ObjectInputStream.resolveClass(Unknown Source) at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source) at java.io .ObjectInputStream.readClassDesc(Unknown Source) 在 java.io.ObjectInputStream.readOrdinaryObject(Unknown Source) 在 java.io。java.io.ObjectInputStream.readSerialData(Unknown Source) at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source) at java.io.ObjectInputStream.java.io.ObjectInputStream.defaultReadFields(Unknown Source) 的 ObjectInputStream.readObject0(Unknown Source)。 readObject0(Unknown Source) at java.io.ObjectInputStream.readObject(Unknown Source) at core.ProcedureSetup.load(ProcedureSetup.java:57) at core.Engine.main(Engine.java:25)核心.Engine.main(Engine.java:25) 处的 ProcedureSetup.load(ProcedureSetup.java:57)核心.Engine.main(Engine.java:25) 处的 ProcedureSetup.load(ProcedureSetup.java:57)
我实例化对象并从“tp”类中调用“ProcedureSetup”的“save”方法。
ProcedureSetup ps=new ProcedureSetup(new Procedure(){ public void doStuff(){ System.out.println("Stuff is being done"); }});
ps.save();
但是我从具有-ALL-必需代码但“tp”的不同程序集合中加载
ProcedureSetup ps=new ProcedureSetup();
ps.load();
类中的对象保存和加载:
public void load(){
String path=Operator.persistentGetFile();//gets the file path
ObjectInputStream ois=null;
FileInputStream fin=null;
ProcedureSetup temp=null;
try {
fin = new FileInputStream(path);
ois = new ObjectInputStream(fin);
temp=(ProcedureSetup) ois.readObject();
ois.close();
fin.close();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
if(ois!=null){
try {
ois.close();
} catch (IOException e) {}
}
if(fin!=null){
try {
fin.close();
} catch (IOException e) {}
}
if(temp!=null){
a=temp.a;
}else{
load();//If a load is failed, restart process.
}
}
public void save(){
String path=Operator.persistentGetDirectory();//get directory to save to
String input = JOptionPane.showInputDialog(this, "Enter the File name:");
ObjectOutputStream oos=null;
FileOutputStream fon=null;
try {
fon = new FileOutputStream(path+input+".obj");
oos = new ObjectOutputStream(fon);
try {
oos.writeObject(this);
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
oos.close();
fon.close();
} catch (IOException e) {
e.printStackTrace();
}
if(oos!=null){
try {
oos.close();
} catch (IOException e) {}
}
if(fon!=null){
try {
fon.close();
} catch (IOException e) {}
}
}
我的问题是:
为什么会发生这些错误?
为什么(如有必要)我的类路径中需要有“tp”?
如果实际上有一种方法可以将对象保存在其当前状态而无需在类路径中使用“tp”,我将如何去做呢?(链接会很可爱)