Hallo ihr Guten!
Ich bin seit einem Jahr in der Programmierung tätig und nun an meine Grenzen gestoßen. Bisher habe ich noch jedes Problem googeln können.
Ich entwickle ein plugin für das java basierte ImageJ (ImageJ API) und brauche eine Klasse die ich speichern und Laden kann. Das Serialisieren habe ich mir natürlich angesehen und versucht anzuwenden (Quellcode weiter unten). Trotzdem gibt die konsole immer einen notserialisable exception aus.
Ist es generell nicht möglich meine Klasse zu speichern oder gibt es eventuell noch andere alternativen?
Herzlichen Dank für eure Hilfe!
Influenza
Ich bin seit einem Jahr in der Programmierung tätig und nun an meine Grenzen gestoßen. Bisher habe ich noch jedes Problem googeln können.
Ich entwickle ein plugin für das java basierte ImageJ (ImageJ API) und brauche eine Klasse die ich speichern und Laden kann. Das Serialisieren habe ich mir natürlich angesehen und versucht anzuwenden (Quellcode weiter unten). Trotzdem gibt die konsole immer einen notserialisable exception aus.
Ist es generell nicht möglich meine Klasse zu speichern oder gibt es eventuell noch andere alternativen?
Herzlichen Dank für eure Hilfe!
Influenza
Java:
import ij.gui.Roi;
import java.awt.Color;
import java.awt.Component;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
public class EvaSer implements Serializable{
/**
*
*/
private static final long serialVersionUID = 3873721584911475388L;
/**
*
*/
/**
*
*/
public int nSpec;
public int nImages;
public List<int[][]> types;
public String evalName;
public String[] specNames;
public String[] typeNames;
public List<String> imageNames;
public List<Roi[][]> rois;
public List<Roi> fixpoints;
public List<File[]> files;
public Roi[] ovrls;
public Color[] specieColors;
public File dir;
public EvaSer(){
this.evalName="new Evaluation "+System.currentTimeMillis();
initLists();
initTypeArrs();
}
private void initTypeArrs() {
typeNames=new String[]{""};
}
public void initLists() {
this.imageNames= new ArrayList<String>();
this.rois= new ArrayList<Roi[][]>();
this.fixpoints= new ArrayList<Roi>();
this.types= new ArrayList<int[][]>();
}
public void save(Component parent) {
System.out.println(this.nSpec);
System.out.println(this.nImages);
System.out.println(this.types.toString());
System.out.println(this.evalName);
System.out.println(this.specNames.toString());
System.out.println(this.typeNames.toString());
System.out.println(this.imageNames.toString());
System.out.println(this.rois.toString());
System.out.println(this.fixpoints.toString());
System.out.println(this.files.toString());
System.out.println(this.ovrls.toString());
System.out.println(this.specieColors.toString());
System.out.println(this.dir);
String path;
path=this.dir.toString();
if(this.evalName==null){
this.evalName=RegularFunctions.getName(parent);
}
path=path+this.evalName+".eva";
ObjectOutputStream oos = null;
FileOutputStream fos = null;
try {
fos = new FileOutputStream(path);
oos = new ObjectOutputStream(fos);
oos.writeObject((Object)this);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (oos != null)
try {
oos.close();
} catch (IOException e) {
}
if (fos != null)
try {
fos.close();
} catch (IOException e) {
}
}
}
public EvaSer load(String path) {
ObjectInputStream ois = null;
FileInputStream fis = null;
Object so= new Object();
try {
fis = new FileInputStream(path);
ois = new ObjectInputStream(fis);
Object obj = ois.readObject();
if (obj instanceof EvaSer) {
so = (EvaSer) obj;
}
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} finally {
if (ois != null)
try {
ois.close();
} catch (IOException e) {
}
if (fis != null)
try {
fis.close();
} catch (IOException e) {
}
}
return (EvaSer) so;
}
}