javaandroidabstractexpandablelistadapter

Can't instantiate ExpandableListAdapter because it is abstract


I am trying to use code from the internet, but when plugging said code into my personal project I am getting the following error:

"ExpandableListAdapter" is abstract; cannot be instantiated

I have tried to do my own research for an answer to my problem but I still haven't been able to fix said problem...

Here is my code:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class MainActivity extends AppCompatActivity {

private ExpandableListView listView;
private ExpandableListAdapter AdapterMedia;
private List<String> listDataHeader;
private HashMap<String,List<String>> listHash;

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

    listView = (ExpandableListView)findViewById(R.id.);
    initData();


    AdapterMedia = new ExpandableListAdapter(this, listDataHeader, listHash);


    listView.setAdapter(AdapterMedia);
}

Any help would be greatly appreciated!


Solution

  • @deHaar is correct, ExpandableListAdapter is an interface and can't be directly instantiated. I would checkout this tutorial for more information.

    Also, as a side note in general: findViewById(R.id.<id>;) needs an associated <id> defined from your corresponding XML layout: setContentView(R.layout.<layout>);

    Hopefully that helps!