我在下面的代码中遇到了一个错误:
HashMap map = new HashMap();
map.put("driver", userId);
map.put("customer", customerId);
map.put("rating", 0);
map.put("timestamp", getCurrentTimestamp());
map.put("destination", destination);
map.put("location/from/lat", pickupLatLng.latitude);
map.put("location/from/lng", pickupLatLng.longitude);
map.put("location/to/lat", destinationLatLng.latitude);
map.put("location/to/lng", destinationLatLng.longitude);
map.put("distance", rideDistance);
historyRef.child(requestId).updateChildren(map);
他们建议添加以下内容:
在创建哈希映射之前或对于每个纬度和经度,执行if(pickupLatLng.latitude != null && pickupLatLng.longitude != null && destinationLatLng.latitude != null && destinationLatLng.longitude != null)。
但是当我尝试这样做时,我遇到了以下错误:运算符!=不能应用于double、null
有人能帮助我吗?
double
是一种原始类型,因此您无法检查其是否为null
。相反,您可以检查它是否为0
或更低的值。 - Darwind