elfoz
elfoz

Reputation: 115

Cannot instantiate the type ExpandableListAdapter

I try to create an ExpandableListView in a navigation drawer. I tried a sample code but i got this error before the compile.

public class MainActivity extends Activity {

     ExpandableListAdapter listAdapter;
    ExpandableListView expListView;
    List<String> listDataHeader;
    HashMap<String, List<String>> listDataChild;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // get the listview
        expListView = (ExpandableListView) findViewById(R.id.left_drawer);

        // preparing list data
        prepareListData();

   listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);

The error is in this line: listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);

Why it says that Cannot instantiate the type ExpandableListAdapter ?

Upvotes: 1

Views: 6015

Answers (3)

Mill
Mill

Reputation: 235

Remove import android.widget.ExpandableListAdapter; or rename your class under this name.

:)

Upvotes: 2

RobinHood
RobinHood

Reputation: 10969

ExpandableListAdapter is also a interface in the android.widget.ExpandableListAdapter It seems that you are importing this, and this is trying to be instantiated instead your local ExpandableListAdapter class.

Rename your ExpandableListAdapter.

Upvotes: 10

Tudor Luca
Tudor Luca

Reputation: 6419

Because ExpandableListAdapter is an interface, aka has no implementation.

Check the documentation for some implementations of ExpandableListAdapter like SimpleExpandableListAdapter .

Upvotes: 0

Related Questions