Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.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
Android 接线员!=不能应用于双精度,空_Android_Null_Double_Latitude Longitude_Uber Api - Fatal编程技术网

Android 接线员!=不能应用于双精度,空

Android 接线员!=不能应用于双精度,空,android,null,double,latitude-longitude,uber-api,Android,Null,Double,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",

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

  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);
他们说要补充:

在创建hashMap之前,或者对于每个纬度和经度,如果(pickupLatLng.latitude!=null&&pickupLatLng.longitude!=null&&destinationLatLng.latitude!=null&&destinationLatLng.longitude!=null&&DestinationLattude!=null&&DestinationLatting.longitude!=null),则执行操作

但是,当我尝试此操作时,会出现以下错误:operator!=不能应用于双精度,空


有人能帮帮我吗?

double是一种基本类型,它不能为null,相反,您可以使用double然后将其与null进行比较。首先,Java double不能为null,也不能与Java null进行比较。(double类型是基元(非引用)类型,基元类型不能为null。)

试试这个

if( pickupLatLng.latitude != 0 && pickupLatLng.longitude != 0 && destinationLatLng.latitude != 0 && destinationLatLng.longitude != 0) 

我想纬度或经度是可以的,而你的pickuplatling或destinationLatLng是空的,并给你NPE,所以我认为你必须使用这段代码

if (pickupLatLng != null && destinationLatLng != null) {}

double
是一种基本类型,因此不能检查它是否为
null
。例如,检查double是否为
0
或更低。因为double是原语而不是对象,所以不能将其与null进行比较。将其与数字(零)进行比较。看这可能是有用的,请分享NPE日志!我猜纬度或经度是好的,这并不能解释为什么OP-get会出现这个错误,所以答案毫无帮助。重新表述您的答案或将其删除。