如果为null,请检查LatLngBounds.Builder [英] Check LatLngBounds.Builder if null

查看:288
本文介绍了如果为null,请检查LatLngBounds.Builder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

LatLngBounds.Builder builder = new LatLngBounds.Builder();
for(int x = firstVisibleItem; x < lastVisibleItem; x++){
    builder.include(temp.getPosition());
}

但是这行抛出错误( java.lang .IllegalStateException:没有包括点

double north = builder.build().northeast.latitude;

这是因为上面的循环根本没有运行所以没有点是包含在构建器中。

This is because the above loop didn't run at all so no points were included in the builder.

如何检查构建器是否至少有一个点?

How can I check if the builder has at least one point?

我试过 builder.build()!= null 这会引发上述错误并且 builder!= null 始终为True。

I tried builder.build()!=null which throws the above error and builder!=null which is always True.

try {} catch(IllegalStateException e){} 问一个!= null 的方式是不是很蠢?微管理?谢谢

try{}catch(IllegalStateException e){ } works. Is it stupid to ask a !=null way? Mico-management? Thanks

推荐答案

您可以创建一个计数器并使用它来验证您至少有一个点。

You can create a counter and use it to verify that you have at least one point.

int counter = 0;
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for(int x = firstVisibleItem; x < lastVisibleItem; x++){
    counter++;
    builder.include(temp.getPosition());
}
if (counter > 0) {
    //use a LatLngBounds.Builder to build the LatLngBounds object
}

这篇关于如果为null,请检查LatLngBounds.Builder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆