【发布时间】:2019-03-01 05:41:56
【问题描述】:
我正在尝试使用来自互联网的代码,但是在将上述代码插入我的个人项目时,我收到以下错误:
“ExpandableListAdapter”是抽象的;无法实例化
我已尝试自行研究以解决我的问题,但我仍然无法解决上述问题...
这是我的代码:
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);
}
任何帮助将不胜感激!
【问题讨论】:
-
您复制的代码是否还包含一个名为
ExpandableListAdapter的类? -
您无法实例化它,因为
ExpandableListAdapter是一个接口。您必须实例化它的一个实现类...请参阅this 并查看已知的间接子类。看看它们也会为您带来一些要使用的直接子类,例如SimpleExpandableListAdapter -
我明白了!我更改了班级的名称._。我的错,谢谢你的帮助!
标签: java android abstract expandablelistadapter