问题
I want to get current location using GPS.
Here is my scenario. My class definition is:
public class UseGps extends Activity implements LocationListener
If Í try to override the LocationListener methods like this
1)
@Override
public void onLocationChanged(Location loc)
2)
@Override
public void onProviderDisabled(String provider)
3)
@Override
public void onProviderEnabled(String provider)
it is giving me compilation error saying
The method onStatusChanged(String, int, Bundle) of type UseGps must override a superclass method remove override.
Same for 2) and 3)
What is wrong here?
回答1:
Assuming that you are using Eclipse do the following to ensure that your compliance level is 1.6.
Go to Project -> Properties -> Java Compiler. There make sure that Compiler compliance level is set to 1.6.
You should set that level as a default value by navigating to Window -> Preferences -> Java -> Compiler. Select 1.6 for Compiler compliance level.
回答2:
Someone should probably explain that:
@Overridewasn't supported for interfaces until Java 1.6.In Java 1.5, you cannot use
@Overrideon a method to indicate it is intended to implement an interface method - the compiler will flag it as an override error. Under Java 1.5, you can use@Overrideonly to indicate that the method is overriding a superclass method.Starting in Java 1.6, you can use
@Overrideto indicate the method is intended to implement an interface method (too bad it wasn't a separate annotation like@Implements).Eclipse has a feature that can ensure your code compiles under a particular version of Java, regardless of what actual version of Java you have installed - this is the
Compiler Compliance Level. If it is set to 1.5, even if your JDK is 1.6, the compiler will flag any code that would not compile under Java 1.5.
来源:https://stackoverflow.com/questions/4883496/unable-to-override-methods-of-locationlistener-class