在Android上崩溃的组项目

时间:2019-06-04 09:27:29

标签: android navigation-drawer

嗨,在下面的代码中,我有不同的标题和子标题。在每个标题中包含不同的子项。

假设如果标题下没有任何孩子,则我的应用每次崩溃。

没有子标题也如何添加标题

例如:假设item1不包含任何子项。如果我单击item1,则我的应用每次崩溃。

有人可以帮我吗?

 private void prepareListData() {
        listDataHeader = new ArrayList<ExpandedMenuModel> ();
        listDataChild = new HashMap<ExpandedMenuModel, List<String>>();

        ExpandedMenuModel item1 = new ExpandedMenuModel();
        item1.setIconName("HOME");
        item1.setIconImg(R.drawable.home);
        listDataHeader.add(item1);
        listDataHeader.get (0);

        ExpandedMenuModel item2 = new ExpandedMenuModel();
        item2.setIconName("BUILDING MANAGEMENT");
        item2.setIconImg(R.drawable.building_floor_room);
        // Adding data header
        listDataHeader.add(item2);

        ExpandedMenuModel item3 = new ExpandedMenuModel();
        item3.setIconName("LIGHT MANAGEMENT");
        item3.setIconImg(R.drawable.building_floor_room);
        listDataHeader.add(item3);

        ExpandedMenuModel item4 = new ExpandedMenuModel();
        item4.setIconName("SCHEDULING");
        item4.setIconImg(R.drawable.building_floor_room);
        listDataHeader.add(item4);

        ExpandedMenuModel item5 = new ExpandedMenuModel();
        item5.setIconName("USER MANAGEMENT");
        item5.setIconImg(R.drawable.username);
        listDataHeader.add(item5);

        ExpandedMenuModel item6 = new ExpandedMenuModel();
        item6.setIconName("ENERGY MANAGEMENT");
        item6.setIconImg(R.drawable.username);
        listDataHeader.add(item6);

        ExpandedMenuModel item7 = new ExpandedMenuModel();
        item7.setIconName("LOGOUT");
        item7.setIconImg(R.drawable.logout_icon);
        listDataHeader.add(item7);

        // Adding child data



        List<String> heading1 = new ArrayList<String>();
        heading1.add("Add Building");
        heading1.add("Add Floor");
        heading1.add("Grouping Luminaries");

        List<String> heading2 = new ArrayList<String>();
        heading2.add("Add Luminaries");
        heading2.add("Assign Luminaries");
        heading2.add("Grouping Luminaries");

        List<String> heading3 = new ArrayList<String>();
        heading3.add("Add Schedules");
        heading3.add("View Schedules");

        List<String> heading4 = new ArrayList<String>();
        heading4.add("Manage Operator");
        heading4.add("Manage Employee");



        listDataChild.put(listDataHeader.get(1), heading1);// Header, Child data
        listDataChild.put(listDataHeader.get(2), heading2);
        listDataChild.put(listDataHeader.get(3), heading3);
        listDataChild.put(listDataHeader.get(4), heading4);

    }

Logcat:

java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
        at com.deepshikha.lightingsystem.ExpandableListAdapter.getChildrenCount(ExpandableListAdapter.java:43)
        at android.widget.ExpandableListConnector.refreshExpGroupMetadataList(ExpandableListConnector.java:563)
        at android.widget.ExpandableListConnector.expandGroup(ExpandableListConnector.java:688)
        at android.widget.ExpandableListView.handleItemClick(ExpandableListView.java:693)
        at android.widget.ExpandableListView.performItemClick(ExpandableListView.java:653)
        at android.widget.AbsListView$PerformClick.run(AbsListView.java:4085)
        at android.widget.AbsListView$10.run(AbsListView.java:6573)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:7000)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)

0 个答案:

没有答案