How to fix " java.lang.NoSuchMethodError: com.google.firebase.database.DatabaseReference.setValue"
How to fix " java.lang.NoSuchMethodError: com.google.firebase.database.DatabaseReference.setValue"
我正在设置我的当前位置 application.Where 我需要设置编码吗?
@Override
public void onLocationChanged(Location location) {
mLastLocation = location;
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(11));
//Geo Fire for current location
String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference refAvailable = FirebaseDatabase.getInstance().getReference("driversAvailable");
DatabaseReference refWorking = FirebaseDatabase.getInstance().getReference("driversWorking");
GeoFire geoFireAvailable = new GeoFire(refAvailable);
GeoFire geoFireWorking = new GeoFire(refWorking);
switch (customerId){
case "":
geoFireWorking.removeLocation(userId);
geoFireAvailable.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude()), new GeoFire.CompletionListener() {
@Override
public void onComplete(String key, DatabaseError error) {
}
});
break;
default:
geoFireAvailable.removeLocation(userId);
geoFireWorking.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude()), new GeoFire.CompletionListener() {
@Override
public void onComplete(String key, DatabaseError error) {
}
});
break;
}
}
以下是我得到的错误:
java.lang.NoSuchMethodError: com.google.firebase.database.DatabaseReference.setValue
at com.firebase.geofire.GeoFire.removeLocation(GeoFire.java:215)
at com.firebase.geofire.GeoFire.removeLocation(GeoFire.java:192)
at com.example.webforest.quickaidlikeuber2nd.DriverMapActivity.onLocationChanged(DriverMapActivity.java:184)
当您使用 setLocation()
方法而不使用 GeoFire.CompletionListener()
时,此错误似乎会自动出现。如果您实施 CompletionListener
,这应该可以解决问题。
因此,替换
geoFire.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude()));
和
geoFire.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude()), new GeoFire.CompletionListener(){ });
编辑 2:
如果您仍然遇到困难,您可能需要适应不同的方法。
替换以下代码:
geoFireAvailable.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude()), new GeoFire.CompletionListener() {
@Override
public void onComplete(String key, DatabaseError error) {
}
});
使用以下代码:
GeoHash geoHash = new GeoHash(new GeoLocation(location.getLatitude(),location.getLongitude()));
Map<String, Object> updates = new HashMap<>();
updates.put("g", geoHash.getGeoHashString());
updates.put("l", Arrays.asList(location.getLatitude(),location.getLongitude()));
geoFireAvailable.setValue(updates,geoHash.getGeoHashString());
Geofire 发生了一些变化,现在要使 removeLocation 起作用,您必须像这样添加一个侦听器:
//after updating
geoFireWorking.removeLocation("id of the node you want to remove", new GeoFire.CompletionListener() {
@Override
public void onComplete(String key, DatabaseError error) {
}
});
我正在设置我的当前位置 application.Where 我需要设置编码吗?
@Override
public void onLocationChanged(Location location) {
mLastLocation = location;
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(11));
//Geo Fire for current location
String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference refAvailable = FirebaseDatabase.getInstance().getReference("driversAvailable");
DatabaseReference refWorking = FirebaseDatabase.getInstance().getReference("driversWorking");
GeoFire geoFireAvailable = new GeoFire(refAvailable);
GeoFire geoFireWorking = new GeoFire(refWorking);
switch (customerId){
case "":
geoFireWorking.removeLocation(userId);
geoFireAvailable.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude()), new GeoFire.CompletionListener() {
@Override
public void onComplete(String key, DatabaseError error) {
}
});
break;
default:
geoFireAvailable.removeLocation(userId);
geoFireWorking.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude()), new GeoFire.CompletionListener() {
@Override
public void onComplete(String key, DatabaseError error) {
}
});
break;
}
}
以下是我得到的错误:
java.lang.NoSuchMethodError: com.google.firebase.database.DatabaseReference.setValue at com.firebase.geofire.GeoFire.removeLocation(GeoFire.java:215) at com.firebase.geofire.GeoFire.removeLocation(GeoFire.java:192) at com.example.webforest.quickaidlikeuber2nd.DriverMapActivity.onLocationChanged(DriverMapActivity.java:184)
当您使用 setLocation()
方法而不使用 GeoFire.CompletionListener()
时,此错误似乎会自动出现。如果您实施 CompletionListener
,这应该可以解决问题。
因此,替换
geoFire.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude()));
和
geoFire.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude()), new GeoFire.CompletionListener(){ });
编辑 2:
如果您仍然遇到困难,您可能需要适应不同的方法。
替换以下代码:
geoFireAvailable.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude()), new GeoFire.CompletionListener() {
@Override
public void onComplete(String key, DatabaseError error) {
}
});
使用以下代码:
GeoHash geoHash = new GeoHash(new GeoLocation(location.getLatitude(),location.getLongitude()));
Map<String, Object> updates = new HashMap<>();
updates.put("g", geoHash.getGeoHashString());
updates.put("l", Arrays.asList(location.getLatitude(),location.getLongitude()));
geoFireAvailable.setValue(updates,geoHash.getGeoHashString());
Geofire 发生了一些变化,现在要使 removeLocation 起作用,您必须像这样添加一个侦听器:
//after updating
geoFireWorking.removeLocation("id of the node you want to remove", new GeoFire.CompletionListener() {
@Override
public void onComplete(String key, DatabaseError error) {
}
});