3

这是我的代码:

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)

我真的不明白为什么会发生这种情况。

4

1 回答 1

2

您的错误可能来自您的 for 语句:

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

您能否发布您的 getPuntos() 函数的代码?您似乎试图从一个空的 ArrayList 中获取一个对象。

于 2013-05-29T09:53:16.477 回答