1

I am trying to write an Android app for deliveries. A big part is finding the current location of the mobile device.

All the tutorial I have followed all give the same error which I can not figure out or understand, I am new to Android Development.

The error I receive is "Error:(76, 5) error: method does not override or implement a method from a supertype".

My code:

public class LoginActivity extends AppCompatActivity {
protected LocationManager locationManager;
protected LocationListener locationListener;
protected Context context;
String tempLocation;
String lat;
String provider;
protected String latitude,longitude;
protected boolean gps_enabled,network_enabled;

public static String pName;
public static String pID;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);


    //Get Input
    etUsername = (EditText) findViewById(R.id.txtLoginUserName);
    etPassword = (EditText) findViewById(R.id.txtLoginPassword);




    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, (LocationListener) this);

}
@Override
public void onLocationChanged(Location location) {
    tempLocation = "Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude();
    TextView lg = (TextView) findViewById(R.id.txtLoginUserName);
    lg.setText(tempLocation);
}

@Override
public void onProviderDisabled(String provider) {
    Log.d("Latitude","disable");
}

@Override
public void onProviderEnabled(String provider) {
    Log.d("Latitude","enable");
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    Log.d("Latitude","status");
}

And My Result Log:

Error:(76, 5) error: method does not override or implement a method from a supertype
Error:(83, 5) error: method does not override or implement a method from a supertype
Error:(88, 5) error: method does not override or implement a method from a supertype
Error:(93, 5) error: method does not override or implement a method from a supertype
:app:compileDebugJavaWithJavac FAILED
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Information:BUILD FAILED
Information:Total time: 1.661 secs
Information:5 errors
Information:0 warnings
Information:See complete output in console

I am using this tutorial.

Any help or advise would be appreciated, as I have tried to use many different answers but non really help so far.

iehrlich
  • 3,572
  • 4
  • 34
  • 43
GoodDisplayName
  • 68
  • 1
  • 14

2 Answers2

1

You are missing the following implements LocationListener in your class...

Use something like this

class LocationActivity extends AppCompatActivity implements LocationListener{

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

@Override
public void onLocationChanged(Location location) {

}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {

}

@Override
public void onProviderEnabled(String provider) {

}

@Override
public void onProviderDisabled(String provider) {

}


}

and then you will be able to achieve what you are trying to....Hope it helped you

Siva agarwal
  • 97
  • 1
  • 8
  • Thanks so much, that worked instantly. Just one last question, I have under my AndroidManifest.xml but receive a Caused by: java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission. error. Any idea as to why? – GoodDisplayName Jun 29 '17 at 03:01
  • Happy to help you...also use the following permission ` ` and check if you have not permitted the permission ...By going to Settings>App>your app >Permissions from your android device or Emulator.. – Siva agarwal Jun 29 '17 at 03:10
0

Possible duplicate:

Refer to this post @GoodDisplayName

Android "gps requires ACCESS_FINE_LOCATION" error, even though my manifest file contains this

Ramji Seetharaman
  • 524
  • 4
  • 7
  • 24