Java 从阵列向多边形添加点
当我试图从数组中向Google Maps多边形添加点时,会出现空指针异常Java 从阵列向多边形添加点,java,android,arrays,google-maps,Java,Android,Arrays,Google Maps,当我试图从数组中向Google Maps多边形添加点时,会出现空指针异常 if(inPolygon.check(list[i].vertices, list[i].latCoords, list[i].longCoords, latitude, longitude) != true) { PolygonOptions rectOptions = new PolygonOptions(); for(int n = 0; n <= list[i].ve
if(inPolygon.check(list[i].vertices, list[i].latCoords, list[i].longCoords, latitude, longitude) != true) {
PolygonOptions rectOptions = new PolygonOptions();
for(int n = 0; n <= list[i].vertices; n++){
rectOptions.add(new LatLng(list[i].latCoords[n], list[i].longCoords[n]));
}
}
if(inPolygon.check(列表[i]。顶点,列表[i]。latCoords,列表[i]。longCoords,纬度,经度)!=true){
PolygonOptions rectOptions=新PolygonOptions();
对于(int n=0;n我怀疑这就是问题所在:
for(int n = 0; n <= list[i].vertices; n++)
(与longCoords
相同)-因此当n
等于list[i]。顶点
,这可能是空引用
我怀疑您希望循环检查严格小于(这更常见):
for(int n=0;n
异常发生在哪里,您确定list
是非空的并且只包含非空引用吗?LogCat指向将点添加到多边形(116)的直线。我认为列表是非空的,因为它包含两个对象。嗯……当我这样做时,我会得到一个不同的错误。“IndexOutofBoundsException:无效的索引0,大小为0”。@RowanK:我怀疑你是在另一个地方得到的,这就是进度。所以接下来你需要看看发生的地方,并解决它。它说我在第121行得到错误,这是我创建polygon=googleMap.addPolygon(rectOptions)的那一行@RowanK.:你甚至还没有向我们展示过那段代码……你应该试着自己诊断一下,如果你不能找出问题所在,就用所有相关的代码问一个新问题。
list[i].latCoords[n]
for (int n = 0; n < list[i].vertices; n++)