Android 为什么我是Bean.getAccountname()';关于空对象引用
我想做一个expandablelistview,但当我点击组列表时,它崩溃了Android 为什么我是Bean.getAccountname()';关于空对象引用,android,Android,我想做一个expandablelistview,但当我点击组列表时,它崩溃了 E/AndroidRuntime: FATAL EXCEPTION: main Process: com.tooozy.accountbook, PID: 16291 java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.tooozy.accountbook.model.Account
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.tooozy.accountbook, PID: 16291
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.tooozy.accountbook.model.AccountDetailBean.getAccountname()' on a null object reference
at com.tooozy.accountbook.Adapter.Adapter_AccountItem.getChildView(Adapter_AccountItem.java:98)
at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:451)
....
以下是我的expandablelistview适配器代码
根据第一条错误消息(com.tooozy.accountbook.Adapter.Adapter\u AccountItem.getChildView(Adapter\u AccountItem.java:98))
我可以看到该组并将消息放入其中,但我无法扩展它
这里是我的列表视图代码
listview = view.findViewById(R.id.expandablelistview);
Group = new ArrayList<>();
Child = new HashMap<>();
Group.add("f");
Group.add("s");
Group.add("t");
Group.add("f");
Group.add("fif");
Group.add("six");
Group.add("sev");
Group.add("eight");
AllData = MyApplication.mdbmaster.mAccountDetailDao.mare();
Child.put(Group.get(0),AllData.get(0));
Child.put(Group.get(1),AllData.get(1));
Child.put(Group.get(2),AllData.get(2));
Child.put(Group.get(3),AllData.get(3));
Child.put(Group.get(4),AllData.get(4));
Child.put(Group.get(5),AllData.get(5));
Child.put(Group.get(6),AllData.get(6));
Child.put(Group.get(7),AllData.get(7));
adapter_accountItem = new Adapter_AccountItem(Group, Child,this.getContext());
listview.setAdapter(adapter_accountItem);
listview=view.findviewbyd(R.id.expandablelistview);
组=新的ArrayList();
Child=newhashmap();
集团。添加(“f”);
集团。添加(“s”);
集团。添加(“t”);
集团。添加(“f”);
集团。添加(“fif”);
集团。添加(“六”);
集团。添加(“sev”);
集团增加(“八”);
AllData=MyApplication.mdbmaster.mAccountDetailDao.mare();
Child.put(Group.get(0),AllData.get(0));
Child.put(Group.get(1),AllData.get(1));
Child.put(Group.get(2),AllData.get(2));
Child.put(Group.get(3),AllData.get(3));
Child.put(Group.get(4),AllData.get(4));
Child.put(Group.get(5),AllData.get(5));
Child.put(Group.get(6),AllData.get(6));
Child.put(Group.get(7),AllData.get(7));
adapter_accountItem=新适配器_accountItem(组、子项、this.getContext());
setAdapter(adapter\u accountItem);
detailBean为空。尝试研究如何初始化它!调试代码,就可以找到错误。可能您正试图从detailBean获取空对象
listview = view.findViewById(R.id.expandablelistview);
Group = new ArrayList<>();
Child = new HashMap<>();
Group.add("f");
Group.add("s");
Group.add("t");
Group.add("f");
Group.add("fif");
Group.add("six");
Group.add("sev");
Group.add("eight");
AllData = MyApplication.mdbmaster.mAccountDetailDao.mare();
Child.put(Group.get(0),AllData.get(0));
Child.put(Group.get(1),AllData.get(1));
Child.put(Group.get(2),AllData.get(2));
Child.put(Group.get(3),AllData.get(3));
Child.put(Group.get(4),AllData.get(4));
Child.put(Group.get(5),AllData.get(5));
Child.put(Group.get(6),AllData.get(6));
Child.put(Group.get(7),AllData.get(7));
adapter_accountItem = new Adapter_AccountItem(Group, Child,this.getContext());
listview.setAdapter(adapter_accountItem);