gpt4 book ai didi

java - 如果为空,则检查 LatLngBounds.Builder

转载 作者:太空宇宙 更新时间:2023-11-03 11:57:55 25 4
gpt4 key购买 nike

这是我的代码:

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

但是这一行抛出一个错误(java.lang.IllegalStateException: no included points
:

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

这是因为上面的循环根本没有运行,所以 builder 中没有包含任何点。

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

我尝试了抛出上述错误的 builder.build()!=null 和始终为 True 的 builder!=null

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

最佳答案

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

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
}

关于java - 如果为空,则检查 LatLngBounds.Builder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21667506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com