Today I've finally got my facebook implementation working and when I started to implement it in my application I g开发者_如何学JAVAet the following errors over @Override.
The method onComplete(Bundle) of type FBConnectionActivity.LoginDialogListener must override a superclass method
If I remove the @Override the error is solved, but I would like to understand why it is complaining about this in one application and not the other.
I've got the following code.
public abstract class FBConnectionActivity extends Activity {
private class LoginDialogListener implements DialogListener {
@Override
public void onComplete(Bundle values) {
Log.d(TAG, "LoginONComplete");
String token = mFacebook.getAccessToken();
long token_expires = mFacebook.getAccessExpires();
Log.d(TAG, "AccessToken: " + token);
Log.d(TAG, "AccessExpires: " + token_expires);
sharedPrefs = PreferenceManager
.getDefaultSharedPreferences(mContext);
sharedPrefs.edit().putLong("access_expires", token_expires)
.commit();
sharedPrefs.edit().putString("access_token", token).commit();
mAsyncRunner.request("me", new IDRequestListener());
}
@Override
public void onFacebookError(FacebookError e) {
Log.d(TAG, "FacebookError: " + e.getMessage());
}
@Override
public void onError(DialogError e) {
Log.d(TAG, "Error: " + e.getMessage());
}
@Override
public void onCancel() {
Log.d(TAG, "OnCancel");
}
}
...
}
This is only a part of the code where the error does occur. But this doesn't have any errors in one application and does have errors in the other.
After some searching I've found that they've change something between Java 5 and 6. But I suppose that my application in eclipse use the same java environment.
Hopefully someone can explain why this is.
Thanks a lot!
Normally that message would indicate that your method signature differs from the method that it is overriding. However, looking at the source for DialogListener, your methods look correct.
In Java 5 you could not use the @Override
annotation with methods that implemented an interface, only with actual overrides of methods from a super class. This changed in Java 6 so that you can now use it in both contexts.
If you are compiling with Java 5 (or setting the compiler's -source
option to expect Java 5 source) that might be the cause of the problem (if it is it should be complaining about all 4 methods). In this case the only solution is to remove the annotations.
精彩评论