Geofire callback error

331 Views Asked by At

I am trying to use the getLocation() method from GeoFire, and it requires two callbacks. However, I am having Method does not override method from its superclass error with the @Override onLocationResult() and onCancelled(). How to fix this?

Note: My class extends Fragment, and the getLocation() is within onCreateView().

Code:

public class Browse extends Fragment {
    ...
    private DatabaseReference mDatabase; // NEW
    private GeoFire geoFire;
    private String businessID;
    ...

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_browse, container, false);

        SharedPreferences businessID1 = getActivity().getSharedPreferences("BUSINESS_ID", Context.MODE_PRIVATE);
        businessID = businessID1.getString("businessID", "businessIDNotFound");

        mDatabase = FirebaseDatabase.getInstance().getReference().child("geo_fire"); // NEW

        GeoFire geoFire = new GeoFire(mDatabase); // NEW

        geoFire.getLocation(businessID, new LocationCallback() {
            @Override <<<--ERROR HERE !
            public void onLocationResult(String key, GeoLocation location) {
                if (location != null) {
                    System.out.println(String.format("The location for key %s is [%f,%f]", key, location.latitude, location.longitude));
                } else {
                    System.out.println(String.format("There is no location for key %s in GeoFire", key));
                }
            }

            @Override <<<--ERROR HERE !
            public void onCancelled(DatabaseError databaseError) {
                System.err.println("There was an error getting the GeoFire location: " + databaseError);
            }
        });


        return rootView;
    }
}

EDIT: My gradle build error:

Error:(90, 13) error: method does not override or implement a method from a supertype

Error:(99, 13) error: method does not override or implement a method from a supertype

Error:(89, 41) error: incompatible types: cannot be converted to com.firebase.geofire.LocationCallback

Dependency: compile 'com.firebase:geofire-android:2.1.1'

1

There are 1 best solutions below

13
On BEST ANSWER

This is happening because you didn't initialize GeoFire. In order to have access to GeoFire's methods, you need to create a new object of the class like this:

GeoFire geoFire = new GeoFire(yourDatabaseReference.child(user.getUid()));

Then you can use the setter and getters. Please see this example.

Edit: Seeing your updated code, the problem is that you are overriding the onCancelled() method in an incorrect way. You need to change this line of code:

public void onCancelled(DatabaseError databaseError) {

with

public void onCancelled(com.firebase.client.FirebaseError firebaseError) {

The argument is of type FirebaseError and not DatabaseError.

Also try to do the following steps with Android Studio. In the activy in which you get the error, remove both methods, onLocationResult() and onCancelled. Then press CTRL+O -> choose both methods -> click Ok. This will helps you override both methods in a correct way.

Later Edit: After many tries, the solution that solved the problem was to update all Firebase dependencies to the last version, which is for the moment 11.2.0. Because GeoFire 2.x is based on the new 3.x release of Firebase, it will work with latest Firebase Android SDK version. In this case 11.2.0.