0

Iv'e been searching a bit and couldn't find an answer... I've created a class and successfully saved an ArrayList of my class to a file but when I'm trying to read this file I keep on getting:

E/Reading file(14768): java.io.WriteAbortedException: Read an exception; java.io.NotSerializableException: il.co.hyperactive.callmaagansmallgate.Gate

here is my class:

public class Gate implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 3L;
    private double latitude;
    private double longitude;
    private String name;
    private String phoneNumber;

    public Gate(String name, double longitude, double latitude,
            String phoneNumber) {
        this.name = name;
        this.longitude = longitude;
        this.latitude = latitude;
        this.phoneNumber = phoneNumber;
    }

    public Gate(String name) {
        this.name = name;
    }

    public void setPlace(double latitude, double longitude) {
        this.longitude = longitude;
        this.latitude = latitude;
    }

    public String toString() {
        return name + "\nLatitude:" + latitude + "\nLongitude:" + longitude
                + "\nNumber:" + phoneNumber;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public double getLongitude() {
        return longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }
}
almightyGOSU
  • 3,731
  • 6
  • 31
  • 41
RawKnee
  • 324
  • 3
  • 11
  • can you try recompiling it once again – jmj Jul 14 '14 at 02:08
  • Where did **java.io.WriteAbortedException** come from here, is that the contents of your file? – Elliott Frisch Jul 14 '14 at 02:12
  • You might check this answer for some info: http://stackoverflow.com/questions/17885968/java-io-notserializableexception-unable-to-deserialize-hashmap-in-java – Mike M. Jul 14 '14 at 03:46
  • Jigar, I built it and recompiled it for several times.. Elliot, the exception thrown while i tried to read a saved file with an object of this class in the internal storage. Mike, I already saw this post - didn't help me ... thx to you all anyways – RawKnee Jul 14 '14 at 23:17

1 Answers1

0

Serializable needs a default constructor, no arguments. So be sure to add:

public Gate(){
}

This is needed because the compiler only generates a default constructor if there is not one specified. Serialization always calls the default constructor and then fills the object up via getters and setters.

ThMBc
  • 794
  • 13
  • 18