2013-05-29 71 views
3

這是我的代碼:IndexOutOfBoundsException異常到地圖

final PolygonOptions options = new PolygonOptions(); 
options.strokeColor(Color.argb(strokeAlpha, r, g, b)); 
options.fillColor(Color.argb(fillAlpha, r, g, b)); 
for (final Punto p : c.getPuntos()) { 
    options.add(p.getLatLng()); 
} 
map.getMap().addPolygon(options) 

而且我不斷收到此異常:

05-29 11:40:04.531: E/MapScreen_(11196): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0 
05-29 11:40:04.531: E/MapScreen_(11196): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251) 
05-29 11:40:04.531: E/MapScreen_(11196): at java.util.ArrayList.get(ArrayList.java:304) 
05-29 11:40:04.531: E/MapScreen_(11196): at maps.aj.bs.c(Unknown Source) 
05-29 11:40:04.531: E/MapScreen_(11196): at maps.aj.bs.o(Unknown Source) 
05-29 11:40:04.531: E/MapScreen_(11196): at maps.aj.bq.b(Unknown Source) 
05-29 11:40:04.531: E/MapScreen_(11196): at maps.aj.bq.a(Unknown Source) 
05-29 11:40:04.531: E/MapScreen_(11196): at maps.aj.al.a(Unknown Source) 
05-29 11:40:04.531: E/MapScreen_(11196): at bcn.onTransact(SourceFile:152) 
05-29 11:40:04.531: E/MapScreen_(11196): at android.os.Binder.transact(Binder.java:310) 
05-29 11:40:04.531: E/MapScreen_(11196): at com.google.android.gms.maps.internal.IGoogleMapDelegate$a$a.addPolygon(Unknown Source) 
05-29 11:40:04.531: E/MapScreen_(11196): at com.google.android.gms.maps.GoogleMap.addPolygon(Unknown Source) 
05-29 11:40:04.531: E/MapScreen_(11196): at com.cidaut.blueparking.MapScreen.editaCalleEnMapa(MapScreen.java:462) 
05-29 11:40:04.531: E/MapScreen_(11196): at com.cidaut.blueparking.MapScreen_.access$21(MapScreen_.java:1) 
05-29 11:40:04.531: E/MapScreen_(11196): at com.cidaut.blueparking.MapScreen_$24.run(MapScreen_.java:562) 
05-29 11:40:04.531: E/MapScreen_(11196): at android.os.Handler.handleCallback(Handler.java:725) 
05-29 11:40:04.531: E/MapScreen_(11196): at android.os.Handler.dispatchMessage(Handler.java:92) 
05-29 11:40:04.531: E/MapScreen_(11196): at android.os.Looper.loop(Looper.java:137) 
05-29 11:40:04.531: E/MapScreen_(11196): at android.app.ActivityThread.main(ActivityThread.java:5041) 
05-29 11:40:04.531: E/MapScreen_(11196): at java.lang.reflect.Method.invokeNative(Native Method) 
05-29 11:40:04.531: E/MapScreen_(11196): at java.lang.reflect.Method.invoke(Method.java:511) 
05-29 11:40:04.531: E/MapScreen_(11196): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
05-29 11:40:04.531: E/MapScreen_(11196): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
05-29 11:40:04.531: E/MapScreen_(11196): at dalvik.system.NativeStart.main(Native Method) 

我真的不明白爲什麼這會發生。

+0

嘗試在調試模式下運行。也許c.getPuntos()返回一個emply數組 – Dolphin

回答

2

你的錯誤可能來自你的語句:

for (final Punto p : c.getPuntos()) 

能否請您發表您的getPuntos()函數的代碼?看起來你試圖從一個空的ArrayList中獲取一個對象。

+0

我添加了一個'size == 0'檢查,然後添加多邊形並且錯誤消失了。謝謝! – razielsarafan

+0

(拋出錯誤時它們可能更明確一些) – razielsarafan

相關問題