简体   繁体   中英

Why can't I override onConfigurationChanged?

I'm trying to override the method onConfigurationChanged and I get the error:

The method onConfigurationChanged(Configuration) of type BaseActivity must override or implement a supertype method

Here is my BaseActivity.java:

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;

public class BaseActivity extends Activity 
{
    protected View.OnClickListener mButtonListenerUPP;
    protected View.OnClickListener mButtonListenerALT;
    protected View.OnClickListener mButtonListenerNAV;
    protected View.OnClickListener mButtonListenerHIS;

    @Override
    public void setContentView(int layoutResID) 
    {
        super.setContentView(layoutResID);
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) 
    {
      setContentView(R.layout.main);
    }
}

A lot of posts on the Internet are saying that I can override this method... Any ideas?

Have you got android.content.res.Configuration in your import statements? Eclipse can insert imports automatically if you press Ctrl+Shift+O.

If that's missing, the compiler will be unable to recognise that you're legitimately overriding the superclass method and so will throw an error.

Let me guess. SuperNotCalledException.

@Override
public void onConfigurationChanged(Configuration newConfig)
{      
    super.onConfigurationChanged(newConfig); // add this line
    setContentView(R.layout.main);
}

Maybe there is a problem with the @Override annotation. Are you sure that both methods annotated with @Override are defined in Activity?

If not you have to remove the respective @Override annotation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM