Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 表格列表在哪里变为空?为什么?_Java_Android_Expandablelistview_Expandablelistadapter - Fatal编程技术网

Java 表格列表在哪里变为空?为什么?

Java 表格列表在哪里变为空?为什么?,java,android,expandablelistview,expandablelistadapter,Java,Android,Expandablelistview,Expandablelistadapter,我正在实现一个适配器来获取List和Hashmap,并将它们分别转换为可扩展ListView的头文件和子文件。在构造函数的日志语句中,它显示值正在成功地传输到本地列表。但随后它突然变为空 我无法准确指出哪里出了问题,哪里出了问题。请帮忙 下面是我的适配器类代码: class ExpandableListViewAdapterDemo extends BaseExpandableListAdapter{ Context context = null; private List<String

我正在实现一个适配器来获取List和Hashmap,并将它们分别转换为可扩展ListView的头文件和子文件。在构造函数的日志语句中,它显示值正在成功地传输到本地列表。但随后它突然变为空

我无法准确指出哪里出了问题,哪里出了问题。请帮忙

下面是我的适配器类代码:

class ExpandableListViewAdapterDemo extends BaseExpandableListAdapter{

Context context = null;
private List<String> headersList;//semester's name and year
private HashMap<String, List<String>> tableList;//course names with its grades and gpa

static final String TAG = "**Adapter Demo**";

ExpandableListViewAdapterDemo(Context context, List<String> list,
                              HashMap<String, List<String>> hashMap){
    this.context = context;
    headersList = list;
    tableList = hashMap;
    Log.e(TAG, "hashmap list value = "+hashMap.get("Spring 2016"));
    Log.e(TAG, "initial table list value = "+tableList.get("Spring 2016"));
    printMap(tableList);
    //printAll();
    Log.e(TAG, "groupCount = "+getGroupCount());

}

void printAll(){
    Log.e(TAG, "headers count = "+headersList.size());
    for (int i = 0; i < headersList.size() ; i++) {
        Log.e(TAG, "header at i="+i+" ,"+headersList.get(i));
    }
    printMap(tableList);
}

private static void printMap(HashMap mp) {
    Iterator it = mp.entrySet().iterator();
    while (it.hasNext()) {
        HashMap.Entry pair = (HashMap.Entry)it.next();
        Log.e(TAG, "#253 : "+pair.getKey() + " = " + pair.getValue());
        it.remove(); // avoids a ConcurrentModificationException
    }
}

@Override
public int getGroupCount() {
    Log.e(TAG, "#299 : table list value = "+tableList.get("Spring 2016"));
    return headersList.size();
}

@Override
public int getChildrenCount(int i) {
    //Log.e(TAG, "at i="+i+" "+headersList.get(i));
    int returns = 0;
    Log.e(TAG, "#307 : table list value = "+tableList.get("Spring 2016"));
    if (tableList.get(headersList.get(i)) != null)
        returns = tableList.get(headersList.get(i)).size();
    else
        Log.e(TAG, "tableList is null");
    Log.e(TAG, "details size = "+returns);
    Log.e(TAG, "group count = "+getGroupCount());
    int tosubtract = 2 * getGroupCount();
    if (returns>tosubtract)
        returns = returns - tosubtract - 2;
    Log.e(TAG, "child count returns = "+String.valueOf(returns) );
    return i;
}

@Override
public Object getGroup(int i) {
    Log.e(TAG, "#323 : table list value = "+tableList.get("Spring 2016"));
    return headersList.get(i);
}

@Override
public Object getChild(int i, int i1) {
    Log.e(TAG, "#329 : table list value = "+tableList.get("Spring 2016"));
    return tableList.get(headersList.get(i)).get(i1);
}

@Override
public long getGroupId(int i) {
    Log.e(TAG, "#335 : table list value = "+tableList.get("Spring 2016"));
    return i;
}

@Override
public long getChildId(int i, int i1) {
    Log.e(TAG, "#340 : table list value = "+tableList.get("Spring 2016"));
    return i1;
}

@Override
public boolean hasStableIds() {
    Log.e(TAG, "#347 : table list value = "+tableList.get("Spring 2016"));
    return false;
}

@Override
public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
    Log.e(TAG, "#353 : table list value = "+tableList.get("Spring 2016"));
    String semesterTitle = (String) getGroup(i);
    if (view == null){
        LayoutInflater inf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inf.inflate(R.layout.previous_semesters_result_list_headers, null);
    }

    TextView semesterName = (TextView) view.findViewById(R.id.semester_name);
    semesterName.setText(semesterTitle);
    return view;
}

@Override
public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
    Log.e(TAG, "#367 : table list value = "+tableList.get("Spring 2016"));
    String courseIdTitle = (String) getChild(i, i1);
    String gpa = (String) getChild(i, i1+getChildrenCount(i));//previously i1+4
    String grade = (String) getChild(i, i1+getChildrenCount(i)+getChildrenCount(i));
    if (view == null){
        LayoutInflater inf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inf.inflate(R.layout.previous_semesters_results_list_child, null);
    }
    TextView courseIdValue = (TextView) view.findViewById(R.id.course_id_column_value);
    courseIdValue.setText(courseIdTitle);
    TextView gradeValue = (TextView) view.findViewById(R.id.grade_column_value);
    gradeValue.setText(grade);
    TextView gpaValue = (TextView) view.findViewById(R.id.gpa_column_value);
    gpaValue.setText(gpa);
    return view;
}

@Override
public boolean isChildSelectable(int i, int i1) {
    Log.e(TAG, "#386 : table list value = "+tableList.get("Spring 2016"));
    return true;
}
}
class ExpandableListViewAdapterDemo扩展了BaseExpandableListAdapter{
Context=null;
私有列表headersList;//学期名称和年份
私有HashMap tableList;//课程名称及其成绩和gpa
静态最终字符串标记=“**适配器演示**”;
ExpandableListViewAdapterDemo(上下文、列表、,
HashMap(HashMap){
this.context=上下文;
headersList=列表;
tableList=哈希映射;
Log.e(标签,“hashmap list value=“+hashmap.get”(“Spring 2016”);
Log.e(标签,“初始表列表值=“+tableList.get”(“2016年春季”);
打印地图(表格列表);
//printAll();
Log.e(标记“groupCount=“+getGroupCount());
}
void printAll(){
Log.e(标记“headers count=“+headersList.size());
对于(int i=0;i子目录)
返回=返回-到子域-2;
Log.e(TAG,“child count returns=“+String.valueOf(returns));
返回i;
}
@凌驾
公共对象getGroup(inti){
Log.e(标记“#323:table list value=“+tableList.get”(“2016年春季”);
返回headersList.get(i);
}
@凌驾
公共对象getChild(inti,inti1){
Log.e(标记“#329:table list value=“+tableList.get”(“2016年春季”);
返回tableList.get(headersList.get(i)).get(i1);
}
@凌驾
公共长getGroupId(inti){
Log.e(标记“#335:table list value=“+tableList.get”(“2016年春季”);
返回i;
}
@凌驾
公共长getChildId(inti,inti1){
Log.e(标记“#340:table list value=“+tableList.get”(“2016年春季”);
返回i1;
}
@凌驾
公共布尔表ID(){
Log.e(标记“#347:table list value=“+tableList.get”(“2016年春季”);
返回false;
}
@凌驾
公共视图getGroupView(int i、布尔b、视图视图、视图组视图组){
Log.e(标记“#353:table list value=“+tableList.get”(“2016年春季”);
字符串semetertitle=(字符串)getGroup(i);
如果(视图==null){
LayoutInflater inf=(LayoutInflater)context.getSystemService(context.LAYOUT\u INFLATER\u SERVICE);
view=inf.inflate(R.layout.previous\u semests\u result\u list\u headers,空);
}
TextView semesterName=(TextView)view.findViewById(R.id.Semmer\u name);
semesterName.setText(semesterTitle);
返回视图;
}
@凌驾
公共视图getChildView(int i、int i1、布尔b、视图视图、视图组视图组){
Log.e(标签“#367:table list value=“+tableList.get”(“2016年春季”);
字符串courseIdTitle=(字符串)getChild(i,i1);
String gpa=(String)getChild(i,i1+getChildrenCount(i));//以前的i1+4
字符串等级=(字符串)getChild(i,i1+getChildrenCount(i)+getChildrenCount(i));
如果(视图==null){
LayoutInflater inf=(LayoutInflater)context.getSystemService(context.LAYOUT\u INFLATER\u SERVICE);
view=inf.inflate(R.layout.previous\u Semess\u results\u list\u child,空);
}
TextView courseIdValue=(TextView)view.findViewById(R.id.course\u id\u column\u value);
courseIdValue.setText(courseIdTitle);
TextView等级值=(TextView)view.findViewById(R.id.grade\u列\u值);
gradeValue.setText(grade);
TextView gpaValue=(TextView)view.findViewById(R.id.gpa\u列\u值);
gpaValue.setText(gpa);
返回视图;
}
@凌驾
公共布尔值是可选择的(int i,int i1){
Log.e(标记“#386:table list value=“+tableList.get”(“2016年春季”);
返回true;
}
}
这是我的日志:

您在打印地图时删除了该项目

it.remove(); // avoids a ConcurrentModificationException
只要去掉这个就行了

private static void printMap(HashMap mp) {
    Iterator it = mp.entrySet().iterator();
    while (it.hasNext()) {
        HashMap.Entry pair = (HashMap.Entry)it.next();
        Log.e(TAG, "#253 : "+pair.getKey() + " = " + pair.getValue());
        //it.remove(); // avoids a ConcurrentModificationException
    }
}

您在打印地图时删除了该项目

it.remove(); // avoids a ConcurrentModificationException
只要去掉这个就行了

private static void printMap(HashMap mp) {
    Iterator it = mp.entrySet().iterator();
    while (it.hasNext()) {
        HashMap.Entry pair = (HashMap.Entry)it.next();
        Log.e(TAG, "#253 : "+pair.getKey() + " = " + pair.getValue());
        //it.remove(); // avoids a ConcurrentModificationException
    }
}

在方法
printMap()
中,
while
块中的最后一条语句是

 it.remove(); // avoids a ConcurrentModificationException
此语句可能不会导致
异常
,但会从
HashMap
中删除当前条目。那么执行之后呢,

printMap(tableList);

ExpandableListViewAdapterDemo
构造函数中,表格列表将为空

在方法
printMap()
中,
while
块中的最后一条语句是

 it.remove(); // avoids a ConcurrentModificationException
此语句可能不会导致
异常
,但会从
HashMap
中删除当前条目。那么执行之后呢,

printMap(tableList);

ExpandableListViewAdapterDemo
构造函数中,表格列表将为空

看起来您需要学习使用调试器。请您自己学习一些辅助调试技术。看起来您需要学习t