GeoPoints のリストをシリアライズしてから、再度読み込む必要があります。Web を検索したところ、独自の GeoPoint を実装してシリアライズ可能に実装できることがわかりました。それは機能し、オブジェクトを.serファイルに書き込むことができますが、それを読み返すと、無効なクラス例外が発生し、詳細メッセージが表示されます-元のGeoPointオブジェクトの不正アクセス例外. MyGeoPoint クラスで GeoPoint を適切に拡張していないと思います。誰かが見て、私がどこでエラーを起こしているのか教えてもらえますか?
import com.google.android.maps.GeoPoint;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class MyGeoPoint extends GeoPoint implements Serializable {
static final long serialVersionUID = -3010695769693014199L;
public MyGeoPoint(int latitude, int longitude){
super(latitude, longitude);
}
public MyGeoPoint(){
this(0,0);
}
private void writeObject(ObjectOutputStream s) throws IOException{
s.defaultWriteObject();
}
private void readObject(ObjectInputStream s)
throws java.io.IOException, java.lang.ClassNotFoundException{
s.defaultReadObject();
}
}
そして、それは次のように使用されます
File filex = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator +"floodData.ser");
MyGeoPoint aPoint = new MyGeoPoint();
MyGeoPoint readPoint = null;
//write
try{
FileOutputStream f = new FileOutputStream(filex);
ObjectOutputStream s = new ObjectOutputStream(f);
s.writeObject(aPoint);
s.close();
} catch (IOException e) {
e.printStackTrace();
}
//read
try {
FileInputStream ff = new FileInputStream(filex);
ObjectInputStream ss = new ObjectInputStream(ff);
readPoint = (MyGeoPoint)ss.readObject();
ss.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
//end serialisationtest