Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 哈希集为空_Java_Android - Fatal编程技术网

Java 哈希集为空

Java 哈希集为空,java,android,Java,Android,为什么我的HashSet是空的 LatLng currentLocation = new LatLng(mCurrentLocation.getLatitude(),mCurrentLocation.getLongitude()); GoogleMap googleMap = mSupportMapFragment.getMap(); HashSet<Circle> circles = new HashSet<>(); if (!cir

为什么我的
HashSet
是空的

    LatLng currentLocation = new LatLng(mCurrentLocation.getLatitude(),mCurrentLocation.getLongitude());
    GoogleMap googleMap = mSupportMapFragment.getMap();

    HashSet<Circle> circles = new HashSet<>();

    if (!circles.isEmpty()) {
        for (Circle circle : circles) {
            Toast.makeText(getActivity(), "" + circles.size(), Toast.LENGTH_SHORT).show();
            if (!circle.getCenter().equals(currentLocation)) {
                circle.remove();
                circles.remove(circle);
            }
        }
    }

    Log.d(TAG_MAP, "" + circles.isEmpty() + " " + circles.size());

    Circle circle = googleMap.addCircle(new CircleOptions()
            .radius(CONSTANT.RADIUS)
            .strokeColor(Color.parseColor(CONSTANT.RADIUS_COLOR))
            .strokeWidth(CONSTANT.RADIUS_BORDER)
            .center(currentLocation));

    circles.add(circle);
LatLng currentLocation=new LatLng(mCurrentLocation.getLatitude(),mCurrentLocation.getLongitude());
GoogleMap GoogleMap=mSupportMapFragment.getMap();
HashSet圆圈=新HashSet();
如果(!circles.isEmpty()){
用于(圆:圆){
Toast.makeText(getActivity(),“”+circles.size(),Toast.LENGTH\u SHORT.show();
如果(!circle.getCenter()等于(currentLocation)){
圈。删除();
圆圈。删除(圆圈);
}
}
}
Log.d(TAG_MAP,“+circles.isEmpty()+”+circles.size());
Circle=googleMap.addCircle(新的CircleOptions()
.半径(恒定半径)
.strokeColor(Color.parseColor(常量半径_颜色))
.strokeWidth(恒定半径_边框)
.中心(当前位置));
圆。添加(圆);

我的意思是我甚至在它上面加了一个
圆圈
对象。我不知道怎么了。加上在我的地图上绘制的圆圈

每次代码运行时,您都在创建一个新的空集合:

HashSet<Circle> circles = new HashSet<>();
if (!circles.isEmpty()) {
    // You'll never get in here...
}
HashSet圆圈=新HashSet();
如果(!circles.isEmpty()){
//你永远也进不了这里。。。
}

如果要在调用之间保持相同的集合,则需要它是一个字段,而不是一个局部变量。

@Titus why downvote。请先理解我的代码。那部分是对的。下次我的方法重新运行时,它将是真的。这一部分仅用于取消前面的循环。我认为,当代码的某些部分显然没有按照您的预期工作时,您不应该声称它们是“正确的”。