0
使用Google Maps API for Android(v2),我試圖將一些國家的Polygon近似值存儲到數據結構中,特別是以String作爲鍵的地圖(國家/地區名稱)和PolygonOptions的ArrayList。將元素添加到字符串地圖,Arraylist
該變種是私人和宣稱:
private Map<String, ArrayList<PolygonOptions>> worldMap;
但我的代碼崩潰,當我試圖用PolygonOption來填補它,下面的功能:
private void addSomeCountry() {
ArrayList <PolygonOptions> MyPoli = new ArrayList<PolygonOptions>();
PolygonOptions rectOptions = new PolygonOptions()
.add(new LatLng(42.569962, 1.78172))
.add(new LatLng(42.509438, 1.723611))
.add(new LatLng(42.601944, 1.445833))
.add(new LatLng(42.569962, 1.78172))
.fillColor(Color.TRANSPARENT)
.strokeColor(Color.CYAN);
MyPoli.add(rectOptions);
worldMap.put("Andorra", MyPoli);
}
具體來說,它崩潰出現以下錯誤:
04-04 21:20:30.335 22562-22562/otorrillas.geography E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: otorrillas.geography, PID: 22562
Caused by: java.lang.NullPointerException
at otorrillas.geography.DataSaver.addSomeCountry(DataSaver.java:49)
at otorrillas.geography.DataSaver.onCreate(DataSaver.java:32)
我做錯了什麼?
是的,它的確如此。謝謝 :) – otorrillas 2015-04-04 19:49:52