Caden Ratcliff
Caden Ratcliff

Reputation: 127

The type new AdapterView.OnItemSelectedListener(){} must implement the inherited abstract method error. Eclipse

I am a begginer in android programming and have yet run into another problem. I am making a simple spinner app. Here is the code.

package net.learn2develop.Basicviews6;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

public class BasicViews6Activity extends Activity {
String[] presidents;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    presidents =
            getResources().getStringArray(R.array.presidents_array);
    Spinner s1 = (Spinner) findViewById(R.id.spinner1);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, presidents);

    s1.setAdapter(adapter);
    s1.setOnItemSelectedListener(new OnItemSelectedListener()
    {
        @Override
        public void onItemSelected(AdapterView<?> arg0,
                View arg1, int arg2, long arg3)
        {
            int index = arg0.getSelectedItemPosition();
            Toast.makeText(getBaseContext(),
                    "You have selected item : " + presidents[index],
                    Toast.LENGTH_SHORT).show();
        }

        @Override
        public Void onNothingdSelected(AdapterView<?> arg0) { }

    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.basic_views6, menu);
    return true;
}

}

But It wont let me run it because theses lines of code:

        s1.setOnItemSelectedListener(new OnItemSelectedListener()
public Void onNothingdSelected(AdapterView<?> arg0)

have the error that reads:

The type new AdapterView.OnItemSelectedListener(){} must implement the inherited abstract method AdapterView.OnItemSelectedListener.onNothingSelected(AdapterView)

Could someone enlighten me? Any help will be much appreciated!

Upvotes: 4

Views: 4900

Answers (3)

Hoan Nguyen
Hoan Nguyen

Reputation: 18151

You need to change

s1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()

Upvotes: 1

Ahmad
Ahmad

Reputation: 72603

Your method says onNothingdSelected() but it should be onNothingSelected(). Change that; you spelled it wrong.

Upvotes: 2

SimonSays
SimonSays

Reputation: 10977

void needs to be written with a lower case v.

public void onNothingdSelected(AdapterView<?> arg0) { }

instead of

public Void onNothingdSelected(AdapterView<?> arg0) { }

Upvotes: 3

Related Questions