运算符 != 不能应用于 double、null

Hot*_*ean 3 double null android latitude-longitude uber-api

我在下面的代码中遇到错误:

  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);
Run Code Online (Sandbox Code Playgroud)

他们说要添加:

在创建 hashMap 之前或针对每个纬度和经度执行if(pickupLatLng.latitude != null &&pickupLatLng.longitude != null && destinationLatLng.latitude != null && destinationLatLng.longitude != null) 。

但是当我尝试这个时,我收到以下错误:operator !=无法应用于 double, null

有人能帮助我吗 ?

Sul*_*man 5

double是原始类型,它不能为 null,而是可以使用Double,然后将其与 null 进行比较