Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.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 更新arraylist的值_Java_Android_Arraylist - Fatal编程技术网

Java 更新arraylist的值

Java 更新arraylist的值,java,android,arraylist,Java,Android,Arraylist,我在控制器包中的arraylist中有一个静态数据。这些是我在控制器包中的代码 for(int i=0;i<studentPic.length;i++){ //i want to update the value of zero mStudentModels.add(new StudentModel(studentPic[i],status[i],studentName[i],courseAndYear[i],0)); }

我在控制器包中的arraylist中有一个静态数据。这些是我在控制器包中的代码

       for(int i=0;i<studentPic.length;i++){
          //i want to update the value of zero
         mStudentModels.add(new StudentModel(studentPic[i],status[i],studentName[i],courseAndYear[i],0));
       }

       public List<StudentModel> getStudentModels (){
       return mStudentModels;
       }

看起来需要执行以下检查:

  • studentPic是否为空
  • mStudentModels是否为空(主要是在调用stopCountdown()方法之前是否添加了mStudentModels)

如果它不能解决问题,请提供控制器端代码的更多信息。

听起来像是竞争条件。你确定学生模型是在调用stopCountdown()之前添加的吗?在startCountdown()之后,学生模型应该被调用。问题是,如果我更新了stopCountdown()中的NumOfAbscences,它也应该更新我控制器的值。当然。它应该更新numoffences的值。
     private void stopCountdown() {
    if (mTask != null) {
        mTask.interrupt();
        List<StudentModel> studentModels = studentData.getStudentModels();
        studentData = new StudentData();
        for(int i=0;i<studentModels.size();i++){
            StudentModel studentModel = studentModels.get(i);
            if(studentModels.get(i).getStatus()=="PRESENT"){
                mFirebaseDatabase.child("attendance").child(formattedDate).child("present").push().setValue(studentModel);
            }else if(studentModels.get(i).getStatus()=="LATE"){
                mFirebaseDatabase.child("attendance").child(formattedDate).child("late").push().setValue(studentModel);
            }else{
                 //i want to update the value of  zero here
                int absences = studentModel.getNumOfAbsences();
                studentModel.setNumOfAbsences(absences+1);
                mFirebaseDatabase.child("attendance").child(formattedDate).child("absent").push().setValue(studentModel);
            }
        }


    }
}
private List<StudentModel> mStudentModels;

public void setmStudentModels(List<StudentModel> mStudentModels) {
    this.mStudentModels = mStudentModels;
}

public StudentData(){
    mStudentModels = new ArrayList<>();
    int[] studentPic = {R.drawable.boy1, R.drawable.boy2, R.drawable.girl1, R.drawable.girl2, R.drawable.girl3,
            R.drawable.girl4, R.drawable.girl5, R.drawable.boy3, R.drawable.girl6, R.drawable.girl7,
            R.drawable.boy4, R.drawable.girl8, R.drawable.girl9, R.drawable.girl10, R.drawable.boy5,
            R.drawable.girl1, R.drawable.girl12, R.drawable.girl13, R.drawable.boy6, R.drawable.girl14};

    String[] status = {"ABSENT","LATE","PRESENT","PRESENT","PRESENT","PRESENT","PRESENT","PRESENT","PRESENT","PRESENT","PRESENT","PRESENT",
            "PRESENT","PRESENT","PRESENT","ABSENT","PRESENT","PRESENT","PRESENT","PRESENT"};
    String[] studentName = {"Andy Lim", "Benjamin Adams", "Karen Healey", "Anne Pierre", "Corine Alvarez",
            "Emily Hedrick", "Courtney Quick", "Oscar Renteria", "Ellen Joy", "Jesse Ramer",
            "Jackson Beck", "Alicia Hofer", "Jenae Rupp", "Allison Beitler", "Martin Hofkamp",
            "Emma Ruth", "Kathryn Berg", "Michelle Salgado", "Lewis Caskey", "Elizabeth Core"};
    String[] courseAndYear = {"BSIT-3", "BSIT 2", "BSIT-3","BSCS-3" , "BSCS-2", "BSIT-3", "BSIT-2", "BSIT-3", "BSIT-2", "BSIT-3",
            "BSCS-3", "BSCS-2", "BSCS-3", "BSCS-2", "BSCS-3", "BSIT-3", "BSCS-2", "BSIT-2", "BSCS-3", "BSCS-2"};


    for(int i=0;i<studentPic.length;i++){
         mStudentModels.add(new StudentModel(studentPic[i],status[i],studentName[i],courseAndYear[i],0));
    }




}

public List<StudentModel> getStudentModels (){
    return mStudentModels;
}
public StudentModel(int studentPic, String status, String studentName, String courseAndYear, int numOfAbsences) {
    this.studentPic = studentPic;
    this.status = status;
    this.studentName = studentName;
    this.courseAndYear = courseAndYear;
    this.numOfAbsences = numOfAbsences;
}