Geofire error with setLocation
Asked Answered
G

4

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)

Gawk answered 22/2, 2018 at 14:53 Comment(5)
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 gettingGawk
Please post the dependencies from your app's build.gradle file .. It seems like your error comes from thereChichihaerh
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'Gawk
I have added the dependenciesGawk
had the same problem with version 2.3.0...rolled back to 2.1.1 and worked fineBaliol
N
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.

Neils answered 6/3, 2018 at 11:15 Comment(1)
It seems I have a similar problem, but in JavaScript #60421459Fortier
B
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

Berchtesgaden answered 1/2, 2019 at 3:58 Comment(0)
R
0

Downgrade your geofire dependency from latest version to

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

Retrospective answered 28/4, 2019 at 13:55 Comment(0)
G
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();
    }
});
Goodale answered 15/3, 2020 at 20:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.