How To Fix " Java.lang.NoSuchMethodError: Com.google.firebase.database.DatabaseReference.setValue"
I'm setting up a current location in my application.Where do i need to set the encoding?
@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;
}
}
Following is error which I'm getting:
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)
Answer
This bug appears to manifest automatically when you are using setLocation()
method without the use of GeoFire.CompletionListener()
. If you implement the CompletionListener
, this should resolve the issue.
Therefore, replace
geoFire.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude()));
with
geoFire.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude()), new GeoFire.CompletionListener(){ });
Edit 2:
You may need to adapt to a different approach if you are still encountering difficulties.
Replace the following code:
geoFireAvailable.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude()), new GeoFire.CompletionListener() {
@Override
public void onComplete(String key, DatabaseError error) {
}
});
With the following code:
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());
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View