3

Possible Duplicate:
Why do I get “must override a superclass method” with @Override?

I recently installed the latest Android SDK in a new eclipse set up on a new machine. When I brought over an old project in several places I got a syntax error concerning @Override stating "method suchandsuch of type suchandsuch must override a superclass method". These items were fixed by removing @Override (which I don't think is correct).

I just made my first new project with my new setup and the initial untouched code is giving this error which has me confused.

package com.geeksonhugs.whenimclose;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.NavUtils;
import android.view.MenuItem;

public class ItemListActivity extends FragmentActivity
        implements ItemListFragment.Callbacks {

    private boolean mTwoPane;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_item_list);

        if (findViewById(R.id.item_detail_container) != null) {
            mTwoPane = true;
            ((ItemListFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.item_list))
                    .setActivateOnItemClick(true);
        }
    }

    @Override
    public void onItemSelected(String id) {
        if (mTwoPane) {
            Bundle arguments = new Bundle();
            arguments.putString(ItemDetailFragment.ARG_ITEM_ID, id);
            ItemDetailFragment fragment = new ItemDetailFragment();
            fragment.setArguments(arguments);
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.item_detail_container, fragment)
                    .commit();

        } else {
            Intent detailIntent = new Intent(this, ItemDetailActivity.class);
            detailIntent.putExtra(ItemDetailFragment.ARG_ITEM_ID, id);
            startActivity(detailIntent);
        }
    }
}

The compiler accepts @Override before onCreate but gives the error with onItemSelected. Can someone please clarify what is going on for me please? Again this syntax error does not occur in prior versions?

Community
  • 1
  • 1
Geeks On Hugs
  • 1,591
  • 2
  • 18
  • 31

1 Answers1

6

I think you are using java compiler 1.5, make it 1.6,because @Override of interface's methods is introduced after 1.5.

In Eclipse,

Window -> Preferences -> Java -> Compiler -> Compiler Compliance Level -> select 1.6

wcr4
  • 55
  • 8
Samir Mangroliya
  • 39,918
  • 16
  • 117
  • 134