gpt4 book ai didi

JAVA java.util.ConcurrentModificationException :null Exception

转载 作者:太空宇宙 更新时间:2023-11-04 06:12:25 24 4
gpt4 key购买 nike

我正在处理我的代码并收到“java.util.ConcurrentModificationException”。我用谷歌搜索了它,也知道只有当你尝试修改正在进行的迭代变量时才会出现这样的错误,在我的例子中我没有感觉到。下面是我的代码。

// This line is having an error
for(Statement s: _mConsumableStatements)
{
System.out.println("s:"+s);

Boolean isConflict=false;
Resource uri=s.getSubject();

System.out.println("uri:"+uri);
System.out.println("1");

if(RepStatementsAsHash.containsKey(uri))
{
System.out.println("2");

if(RepStatementsAsHash.get(uri).containsKey(RDFS.LABEL))
RepStatementsAsHash.get(uri).remove(RDFS.LABEL);
else if(RepStatementsAsHash.get(uri).containsKey(RDFS.SUBCLASSOF))
RepStatementsAsHash.get(uri).remove(RDFS.SUBCLASSOF);
else if(RepStatementsAsHash.get(uri).containsKey(RDFS.RANGE))
RepStatementsAsHash.get(uri).remove(RDFS.RANGE);
else if(RepStatementsAsHash.get(uri).containsKey(RDF.TYPE))
{
System.out.println("2.1");

Value RepTypeObject=RepStatementsAsHash.get(uri).get(RDF.TYPE);
Value ConsumableTypeObject=CStatements.get(uri).get(RDF.TYPE);

if (RepTypeObject.stringValue().equals(OWL.CLASS) || RepTypeObject.stringValue().equals(RDFS.CLASS))
{
if(ConsumableTypeObject.stringValue().equals(OWL.DATATYPEPROPERTY) || ConsumableTypeObject.stringValue().equals(OWL.OBJECTPROPERTY) || ConsumableTypeObject.stringValue().equals(RDF.PROPERTY))
{
isConflict=true;
//_mConflictingStatements.add(s);
}
else
{
RepStatementsAsHash.get(uri).remove(RepTypeObject);
}
}
else if(RepTypeObject.stringValue().equals(OWL.DATATYPEPROPERTY) || ConsumableTypeObject.stringValue().equals(OWL.OBJECTPROPERTY) || RepTypeObject.stringValue().equals(RDF.PROPERTY))
{
if (ConsumableTypeObject.stringValue().equals(OWL.CLASS) || ConsumableTypeObject.stringValue().equals(RDFS.CLASS))
{
isConflict=true;
//_mConflictingStatements.add(s);
}
else
{

}
}
else
{
if( !(RepTypeObject.stringValue().equals(OWL.DATATYPEPROPERTY) || ConsumableTypeObject.stringValue().equals(OWL.OBJECTPROPERTY) || RepTypeObject.stringValue().equals(RDF.PROPERTY) || ConsumableTypeObject.stringValue().equals(OWL.CLASS) || ConsumableTypeObject.stringValue().equals(RDFS.CLASS)) )
{
if(RepTypeObject.stringValue()!=ConsumableTypeObject.stringValue())
{
isConflict=true;
}

}
}
System.out.println("2.2");
if(!isConflict)
{
addStatementsInRepository(uri.stringValue(),c_import);
}
} // LABEL-TYPE
}
else // No URI Conflict
addStatementsInRepository(uri.stringValue(),c_import);

System.out.println("3");
}

它显示错误,例如:

11:13:24.405 ERROR - error while importing Sesame data:
java.util.ConcurrentModificationException: null
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:859) ~[na:1.7.0_71]
at java.util.ArrayList$Itr.next(ArrayList.java:831) ~[na:1.7.0_71]
at org.apache.marmotta.platform.core.services.importer.rdf.RDFImporterImpl.importData2(RDFImporterImpl.java:433) [ulysses-core-1.0-alpha-2.jar:1.0-alpha-2]

如何解决?

最佳答案

在这一行中,与代码中的许多其他行一样:RepStatementsAsHash.get(uri).remove(RepTypeObject);,您正在迭代循环,并在迭代时将其删除。您可以使用Iterator迭代列表或映射,然后使用 iterator.remove() 删除元素。

Example

关于JAVA java.util.ConcurrentModificationException :null Exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28534402/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com