-1

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'

ben
  • 159
  • 1
  • 4
  • 15

1 Answers1

2

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.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • I have added 3 lines of code (see //NEW) in edit. The error still occurs. – ben Aug 30 '17 at 09:26
  • It still does not solve it. How does these solve the 'Method does not override method from its superclass error'? – ben Aug 30 '17 at 10:12
  • there is no onCancelled() option. Could you please show a sample code of how it should look like? It would really help. – ben Aug 30 '17 at 10:30
  • [Interface LocationCallback](https://geofire-java.firebaseapp.com/docs/com/firebase/geofire/LocationCallback.html) has two methods `onCancelled(com.firebase.client.FirebaseError firebaseError)` and `onLocationResult(String key, GeoLocation location)` which you need to override. Are you sure that error is coming here and not in another part of your code? – Alex Mamo Aug 30 '17 at 10:38
  • To override those methos, click CTRL+O after the last curly brace -> new LocationCallback() { – Alex Mamo Aug 30 '17 at 10:41
  • I have done that, for some reason onCancelled() is not an option. I have updated my question to include the gradle build errors. – ben Aug 30 '17 at 10:53
  • Please share also the build.gradle file. Not only the error. – Alex Mamo Aug 30 '17 at 10:57
  • what do you mean by build.gradle file (sorry newbie here) – ben Aug 30 '17 at 11:01
  • the file where you import the `dependencies`. Where you Firebase. `compile 'com.firebaseui:firebase-ui-database:1.2.0'` and so on. – Alex Mamo Aug 30 '17 at 11:02
  • Do you have this line of code `compile 'com.google.firebase:firebase-core:11.2.0'`in your dependencies? – Alex Mamo Aug 30 '17 at 11:26
  • I have the 11:0:4 version. – ben Aug 30 '17 at 11:28
  • 1
    You need to update all the to the last version. `geofire-android:2.1.1` works only with version 11.2.0. – Alex Mamo Aug 30 '17 at 11:30
  • That did the trick! Thanks for being so patient! If you update your answer I will accept it! Thanks a bunch! – ben Aug 30 '17 at 11:47