Android @Override error

一个人想着一个人 提交于 2019-12-22 11:22:34

问题


Today I've finally got my facebook implementation working and when I started to implement it in my application I get 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!


回答1:


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.



来源:https://stackoverflow.com/questions/6484527/android-override-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!