Java 如何在ExpandableListView中修复此错误?

Java 如何在ExpandableListView中修复此错误?,java,android,nullpointerexception,expandablelistview,expandablelistadapter,Java,Android,Nullpointerexception,Expandablelistview,Expandablelistadapter,我想从api获取我的exbandableListView的数据。但是,ExpandableListAdapter中存在问题 java public class SSS extends BaseActivity { private DrawerLayout mDrawerLayout; /// Drawer Layout private ExpandableListView listView; private ExpandapleListAdapter listAdapter; private A

我想从
api
获取我的
exbandableListView
的数据。但是,
ExpandableListAdapter
中存在问题

java

public class SSS extends BaseActivity {
private DrawerLayout mDrawerLayout; /// Drawer Layout
private ExpandableListView listView;
private ExpandapleListAdapter listAdapter;
private ArrayList<SSSDataModel> listDataHeader;
private HashMap<String,List<String>> listHash;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sss);
    /// Expandaple List view
    listView = (ExpandableListView)findViewById(R.id.Exp);
   // initData();

    listAdapter = new ExpandapleListAdapter(this,listDataHeader,listHash);
    listView.setAdapter(listAdapter);
    getSSSRequest();

    private void getSSSRequest(){

    startProgress();
    String authorization = SessionHelper.getCustomerTokenWithBearer();

    Call<SSSModel> call = ApiService.apiInterface.getFAQ(authorization);
    call.enqueue(new Callback<SSSModel>() {
        @Override
        public void onResponse(Call<SSSModel> call, Response<SSSModel> response) {
            stopProgress();

            if (response.isSuccessful()){

                listDataHeader.clear();
                listHash.clear();

                if (response.body() != null && response.body().getData().size() > 0){
                   listDataHeader.addAll(response.body().getData());

                }
            }
            else {
                ApiErrorUtils.parseError(response);
            }
        }

        @Override
        public void onFailure(Call<SSSModel> call, Throwable t) {
            stopProgress();
            DialogHelper.showFailedDialog();

        }
    });

   }

   ExpandapleListAdapter.java

    public class ExpandapleListAdapter extends BaseExpandableListAdapter {
private Context context;
private ArrayList<SSSDataModel> listDataHeader;
private HashMap<String,List<String>> listHashMap;

public ExpandapleListAdapter(Context context, ArrayList<SSSDataModel> listDataHeader, HashMap<String, List<String>> listHashMap){
    this.context = context;
    this.listDataHeader = listDataHeader;
    this.listHashMap = listHashMap;
}

@Override
public int getGroupCount() {
    return listDataHeader.size();
}

@Override
public int getChildrenCount(int i) {
    return listHashMap.get(listDataHeader.get(i)).size();
}

@Override
public Object getGroup(int i) {
    return listDataHeader.get(i);
}

@Override
public Object getChild(int i, int i1) {
    return listHashMap.get(listDataHeader.get(i)).get(i1);
}

@Override
public long getGroupId(int i) {
    return i;
}

@Override
public long getChildId(int i, int i1) {
    return i1;
}

@Override
public boolean hasStableIds() {
    return false;
}

@Override
public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
    String headerTitle = (String)getGroup(i);
    if (view == null)
    {
        LayoutInflater inflater = (LayoutInflater)this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.list_group,null);
    }
    TextView lbListHeader = (TextView)view.findViewById(R.id.lblistheader);
    lbListHeader.setTypeface(null, Typeface.BOLD);
    lbListHeader.setText(headerTitle);
    return view;
}

@Override
public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
    final String childText = (String)getChild(i,i1);
    if (view == null)
    {
        LayoutInflater inflater = (LayoutInflater)this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.list_item,null);
    }
    TextView txtListChild = (TextView)view.findViewById(R.id.listitem);
    txtListChild.setText(childText);
    return view;
}

@Override
public boolean isChildSelectable(int i, int i1) {
    return true;
}
}
试试看:

private ArrayList<SSSDataModel> listDataHeader = new ArrayList<>();
private ArrayList listDataHeader=new ArrayList();
您必须初始化ArrayList。我希望这个答案对你有帮助


祝你好运

谢谢。它帮助了我:)
private ArrayList<SSSDataModel> listDataHeader = new ArrayList<>();