5

I am trying to learn geofire I try to implement the SFVehicle app but it is showing error can you please help this is the crucial part of my project

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;
    private static final GeoLocation INITIAL_CENTER = new GeoLocation(37.7789, -122.4017);
    private static final int INITIAL_ZOOM_LEVEL = 14;
    private static String GEO_FIRE_DB = "https://learngoef.firebaseio.com";
    private static String GEO_FIRE_REF = GEO_FIRE_DB+ "/_geofire";



    private Circle searchCircle;
    private GeoFire geoFire;
    private GeoQuery mGeoQuery;

    private Map<String,Marker> markers;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);


        FirebaseDatabase database = FirebaseDatabase.getInstance();
        geoFire = new GeoFire(database.getReference().child("geofire_location"));

        String key = geoFire.getDatabaseReference().push().getKey();
        geoFire.setLocation(key,new GeoLocation(37.7789, -122.4017));




    }

This is the error that I'm getting:

java.lang.NoSuchMethodError: No virtual method setValue(Ljava/lang/Object;Ljava/lang/Object;)Lcom/google/firebase/tasks/Task; in class Lcom/google/firebase/database/DatabaseReference; or its super classes (declaration of 'com.google.firebase.database.DatabaseReference' appears in /data/app/com.myapps.learninggeofire-2/split_lib_dependencies_apk.apk)

rahul motwani
  • 51
  • 1
  • 4
  • java.lang.NoSuchMethodError: No virtual method setValue(Ljava/lang/Object;Ljava/lang/Object;)Lcom/google/firebase/tasks/Task; in class Lcom/google/firebase/database/DatabaseReference; or its super classes (declaration of 'com.google.firebase.database.DatabaseReference' appears in /data/app/com.myapps.learninggeofire-2/split_lib_dependencies_apk.apk) this is the error i am getting – rahul motwani Feb 22 '18 at 14:54
  • Please post the dependencies from your app's `build.gradle` file .. It seems like your error comes from there – Rosário Pereira Fernandes Feb 22 '18 at 22:21
  • implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.google.android.gms:play-services-maps:11.8.0' implementation 'com.google.android.gms:play-services-location:11.8.0' testImplementation 'junit:junit:4.12' compile 'com.firebase:geofire-java:2.3.0' compile 'com.google.firebase:firebase-database:11.8.0' compile 'com.google.firebase:firebase-auth:11.8.0' compile 'com.google.firebase:firebase-core:11.8.0' – rahul motwani Feb 23 '18 at 04:28
  • I have added the dependencies – rahul motwani Feb 23 '18 at 04:29
  • 1
    had the same problem with version 2.3.0...rolled back to 2.1.1 and worked fine – flutter Mar 06 '18 at 16:00

4 Answers4

10

It will work fine if you add a listener in its parameters.As

 geoFire = new GeoFire(database.getReference().child("geofire_location"));

 String key = geoFire.getDatabaseReference().push().getKey();
 geoFire.setLocation(key,new GeoLocation(37.7789, -122.4017)),new 
 GeoFire.CompletionListener(){
            @Override
            public void onComplete(String key, DatabaseError error) {
                //Do some stuff if you want to
            }
        });

I think it might help you.

Kalyan Prusty
  • 130
  • 1
  • 11
  • It seems I have a similar problem, but in JavaScript https://stackoverflow.com/questions/60420959/geofirestore-and-client-side-javascript – nibbana Feb 26 '20 at 21:30
0

I spent 4 hours working on that error

 geoFire.setLocation(userId, new GeoLocation(37.7789, -122.4017)),new 
 GeoFire.CompletionListener(){
            @Override
            public void onComplete(String key, DatabaseError error) {
                Log.e(TAG, "GeoFire Complete");
            }
        });

It still didn't work till I change the firebase dependency to 16.0.4 instead of 16.0.1

elnaka
  • 41
  • 6
0

Downgrade your geofire dependency from latest version to

implementation 'com.firebase:geofire-android:2.1.1'

Jalal Jan Khan
  • 123
  • 1
  • 6
0

Read this - https://github.com/firebase/geofire-java Its support - implementation 'com.firebase:geofire-java:3.0.0' (vertion)

//----------------------------------------code-------------------------------------------

firebaseAuth = FirebaseAuth.getInstance();
firebaseDatabase = FirebaseDatabase.getInstance();
firebaseUser = firebaseAuth.getCurrentUser();


String userid = firebaseUser.getUid();
DatabaseReference ref = firebaseDatabase.getReference("Active Users");
GeoFire geoFire = new GeoFire(ref);


geoFire.setLocation(userid, new GeoLocation(location.getLatitude(), location.getLongitude()), new GeoFire.CompletionListener() {
    @Override
    public void onComplete(String key, DatabaseError error) {
        if (error!=null)
        {
            Toast.makeText(client_dashboard.this,"Can't go Active",Toast.LENGTH_SHORT).show();
        }
        Toast.makeText(client_dashboard.this,"You are Active",Toast.LENGTH_SHORT).show();
    }
});
Niwantha
  • 1
  • 3