Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.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 从对象的集合/更改字段中删除项 public void searchOwner(列表应用程序、字符串所有者){ 一个=null; 预约(临时:预约){ if(所有者同等信号案例(临时所有者名称)){ 系统输出打印LN(温度数据); 温度设置已解决(真); } } } 公共作废支票删除(){ 适用于(预约应用程序:预约){ if(appts.resolved==true){ 任命.罢免(appts); } //增强for循环之前使用的迭代器方法 公共无效checkRemovalI(){ 迭代器it=约会。迭代器(); while(it.hasNext()){ if(it.next().resolved=true){ it.remove(); } } }_Java_Arraylist_Concurrentmodification - Fatal编程技术网

Java 从对象的集合/更改字段中删除项 public void searchOwner(列表应用程序、字符串所有者){ 一个=null; 预约(临时:预约){ if(所有者同等信号案例(临时所有者名称)){ 系统输出打印LN(温度数据); 温度设置已解决(真); } } } 公共作废支票删除(){ 适用于(预约应用程序:预约){ if(appts.resolved==true){ 任命.罢免(appts); } //增强for循环之前使用的迭代器方法 公共无效checkRemovalI(){ 迭代器it=约会。迭代器(); while(it.hasNext()){ if(it.next().resolved=true){ it.remove(); } } }

Java 从对象的集合/更改字段中删除项 public void searchOwner(列表应用程序、字符串所有者){ 一个=null; 预约(临时:预约){ if(所有者同等信号案例(临时所有者名称)){ 系统输出打印LN(温度数据); 温度设置已解决(真); } } } 公共作废支票删除(){ 适用于(预约应用程序:预约){ if(appts.resolved==true){ 任命.罢免(appts); } //增强for循环之前使用的迭代器方法 公共无效checkRemovalI(){ 迭代器it=约会。迭代器(); while(it.hasNext()){ if(it.next().resolved=true){ it.remove(); } } },java,arraylist,concurrentmodification,Java,Arraylist,Concurrentmodification,到目前为止,这就是我遇到的问题。我正在检查预约列表,看看该字段是否(已解决)设置为true,但是我在尝试将resolved=设置为true时,在searchOwner方法期间收到ConcurrentModification异常。我尝试在checkRemove中使用迭代器,而不是增强的for循环,但这也没有帮助。我只需要将约会设置为true的部分checkRem设置为工作oval似乎在实现布尔值解析的更改之前就已经开始工作了。非常感谢您提供的任何帮助。我敢打赌,ConcurrentModifica

到目前为止,这就是我遇到的问题。我正在检查预约列表,看看该字段是否(已解决)设置为true,但是我在尝试将resolved=设置为true时,在searchOwner方法期间收到ConcurrentModification异常。我尝试在checkRemove中使用迭代器,而不是增强的for循环,但这也没有帮助。我只需要将约会设置为true的部分checkRem设置为工作oval似乎在实现布尔值解析的更改之前就已经开始工作了。非常感谢您提供的任何帮助。

我敢打赌,
ConcurrentModificationException
不是在您所说的地方引起的,而是在
checkremove()中引起的
,您可能是在您提到的将
解析
设置为true的行之前调用它,因此您会感到困惑

我这样说只是因为:

public void searchOwner(List<Appointments> appts, String owner) {
    Appointments theOne = null;
    for (Appointments temp : appts) {
        if (owner.equalsIgnoreCase(temp.owner.name)) {
            System.out.println(temp.data);
            temp.setResolved(true);
        }
    }
}

public void checkRemoval() {
    for (Appointments appts : appointments) {
        if (appts.resolved == true) {
            appointments.remove(appts);
        }

//Iterator method used before enhanced for-loop
    public void checkRemovalI(){
    Iterator<Appointments> it = appointments.iterator();
    while(it.hasNext()){
        if(it.next().resolved = true){
            it.remove();
        }
    }
}
是明显的并发修改。在循环中遍历集合时,无法从集合中删除元素。相反,您需要使用:

public void checkremovation(){
迭代器apptsIterator=约会。迭代器();
而(apptsIterator.hasNext()){
if(appts.next().resolved==true)
apptsIterator.remove();//删除通过next()获得的最后一个元素
}

使用for循环引发ConcurrentModification异常,该循环用于修改集合。因此,问题不一定是您发布的代码。您可能在appts列表上有一个循环,该循环正在调用此函数。
发布更多的代码可能会有所帮助。

您可以使用Iterator发布代码吗?我认为您的问题不在于设置resolved=true,而在于checkremove方法。在循环列表时,您不能修改列表。或者将原始列表的副本复制到其他列表中,然后从中继续工作OK,我明白了…很好我让它工作了..switch ed返回到迭代器方法,并更改了调用它的位置,现在它开始工作了..非常感谢!也感谢您的评论..很明显,我在遍历列表时试图从列表中删除项。问题解决了,非常感谢!!
for (Appointments appts : appointments) {
    if (appts.resolved == true) {
        appointments.remove(appts);
    }
}
public void checkRemoval() {
    Iterator<Appointment> apptsIterator = appointments.iterator();
    while (apptsIterator.hasNext()){ 
        if (appts.next().resolved == true) 
            apptsIterator.remove(); //removes the last element you got via next()
    }