Hi, I'm trying to save a serializable class that I've created (Model)
but I don't know what I'm doing wrong because IOEXception is thrown,
can you help me please? here's the code:
File f = new File("/sdcard/");
File[] files = f.listFiles();
String fitx = null;
if(files!=null){
for(int i=0;i<files.length;i++){
File fitxer = files[i];
fitx = fitxer.getName();
if((ID + ".obj").equalsIgnoreCase(fitx)){
entrada = new ObjectInputStream(new
FileInputStream("/sdcard/" + ID + ".obj"));
Model regAct = null;
Object aux = entrada.readObject();
while (aux!=null){
if (aux instanceof Model){
regAct = (Model)aux;
regAct.putCoef(coeficients);
}
ObjectOutputStream sortida = new
ObjectOutputStream(new FileOutputStream("/sdcard/" + ID + ".obj"));
sortida.writeObject(regAct);
sortida.close();
detect=1;
}
}else{
Model mod= new Model (coeficients, ID,
sourceImage);
ObjectOutputStream sortida = new
ObjectOutputStream(new FileOutputStream("/sdcard/" + ID + ".obj"));
sortida.writeObject(mod);
sortida.close();
detect=1;
}
}
}
} catch (StreamCorruptedException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
And here's the class I've created:
import java.io.Serializable;
import android.graphics.Bitmap;
import java.util.Vector;
public class Model implements Serializable {
/**
*
*/
private static final long serialVersionUID =
-1948073164554864537L;
private String nom;
private int ID, n_models, ncoef=100;
private Vector<double[]> models = new Vector<double[]>();
private Bitmap foto;
public Model(double[] x, int n) {
models.add(x);
this.ID = n;
n_models=1;
}
public Model() {
n_models=0;
}
public Model(double[] x, int n, Bitmap img) {
models.add(x);
this.ID = n;
n_models=1;
this.foto=img;
}
public Model(double[] x, String n, Bitmap img) {
models.add(x);
this.nom = n;
n_models=1;
this.foto=img;
}
public Bitmap getImg(){
return foto;
}
public double getDist(double[]a){
double x = 999999999;
double y = 999999999;
for (int i=0;i<n_models;i++){
double[] b = models.get(i);
x= euclidea(a,b);
if (x < y){
y=x;
}
}
return y;
}
public String getNom(){
return nom;
}
public int getID(){
return ID;
}
public void putCoef(double[] x){
models.add(x);
n_models++;
}
public void putImg(Bitmap x){
foto=x;
}
public void putNom(String n){
this.nom=n;
}
public void putID(int x){
this.ID=x;
}
public double manhattan(double [] a, double [] b){
double dist = 0;
for(int i=1; i<ncoef; i++){
dist += Math.abs(a[i]-b[i]);
}
return dist;
}
public double euclidea(double [] a, double [] b){
double dist = 0;
for(int i=1; i<ncoef; i++){
dist += Math.pow((double)(a[i]-b[i]),2.0);
}
return (double)Math.sqrt(dist);
}
}
Thanks
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en