0
我想通過ArrayList<Polygon>
使用intent.putExtra()
。ArrayList可串行化Android
我得到IOException寫入可序列化的對象(名稱= Polygon.polygon)。
多邊形是我製作的類,並且已經在這個類上實現了Serializable。
Intent intent = new Intent(this, Main.class);
intent.putExtra("polygons", (ArrayList<Polygon>)this.polygons);
startActivity(intent);
Polygon類有一個ArrayList<Point>
持有點的名單有幾個getter和setter多邊形,僅此而已。我已經在Polygon類上實現了Serializable,但是我從上面的代碼中得到了這個異常。
public class Polygon implements Serializable{
ArrayList<Point> polygon;
public Polygon(){
polygon = new ArrayList();
}
public int getSize(){
return polygon.size();
}
public ArrayList<Point> getPointArray(){
return this.polygon;
}
public void addPoint(int x, int y, int mapWidth, int mapHeight, int canvasWidth, int canvasHeight){
//going to scale up here
float scaleX = mapWidth/canvasWidth;
float scaleY = mapHeight/canvasHeight;
polygon.add(new Point((int)(x*scaleX),(int)(y*scaleY)));
}
public void removePoint(int index){
polygon.remove(index);
}
}
任何想法?
沒有發佈實施(代碼),你可能不會得到很多有益的幫助。 – Geobits
HI我已經添加了一些代碼。 – jonny
那麼,當我說的時候,我的意思是來自處理序列化的'Polygon'類的代碼。 **但是,**,因爲你發佈了什麼'this.polygons',你爲什麼需要將它轉換爲'ArrayList'?我認爲它已經是那種類型。 –
Geobits