-1
的口組
我試圖做一個dinamical發電集團的ExpandableListView崩潰的ExpandableListView
我宣佈名單的數組,它代表了列表元素對於每個組
List<MarkCell>[] voti_materia;
和我(10是組的最大數量,subject.getCount()是微調器中元素的數量)
voti_materia = new ArrayList[10];
for(int i=0; i<subjects.getCount();i++){
voti_materia[i] = new ArrayList<>();
listDataHeader.add(subjects.getItemAtPosition(i).toString());
}
它的工作原理,它產生在屏幕上適當的羣體,如果我嘗試打開它的工作列表的第一個組,但如果我嘗試打開其他組的應用程序崩潰的NullPointerException異常
java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
at com.aesolutions.schooltools.diary_adapter.ExpandableListAdapter.getChildrenCount(ExpandableListAdapter.java:75)
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:3305)
at android.widget.AbsListView$4.run(AbsListView.java:4228)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6236)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:891)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:781)
在ExpandableListAdapter的這一功能
@Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.size();
}
_listDataChild被聲明爲
private HashMap<String, List<MarkCell>> _listDataChild;
我不明白它爲什麼會崩潰...有人可以幫助我嗎?謝謝大家
嘗試把一個斷點並確保'_listDataChild'具有更正t值 – Tony
@AESolutions您應該發佈完整的堆棧跟蹤。但是從你發佈的內容你應該調試getChildrenCount()返回的內容。特別是如果沒有什麼可以從_listDataChild – portfoliobuilder
確定沒問題,我發佈了完整的堆棧跟蹤...它告訴我_listDataChild的大小是1(它應該是大小4),這是錯誤,但我不知道它爲什麼只有1元素 – AESolutions