好的,所以我正在研究搜索方法,搜索的术语在数据库中运行,匹配的产品被添加到带有2个整数字段的hashMap中.
在制作了hashmap之后,将显示这些项目,但是我无法通过hashmap打印出详细信息
这是我的代码
public HashMap<Integer, Integer> bankSearch = new HashMap<Integer, Integer>();
Run Code Online (Sandbox Code Playgroud)
和使用
Iterator it = bankSearch.entrySet().iterator();
while (it.hasNext()) {
HashMap.Entry pairs = (HashMap.Entry)it.next();
System.out.println(pairs.getKey() + " = " + pairs.getValue());
if (bankItemsN[i] > 254) {
outStream.writeByte(255);
outStream.writeDWord_v2(pairs.getValue());
} else {
outStream.writeByte(pairs.getValue()); // amount
}
if (bankItemsN[i] < 1) {
bankItems[i] = 0;
}
outStream.writeWordBigEndianA(pairs.getKey()); // itemID
}
Run Code Online (Sandbox Code Playgroud)
目前的错误
.\src\client.java:75: cannot find symbol
symbol : class Iterator
location: class client
Iterator it = bankSearch.entrySet().iterator();
^
.\src\client.java:77: java.util.HashMap.Entry is not public in …Run Code Online (Sandbox Code Playgroud) 我运行一个服务器,它有一个处理计时系统的事件处理程序当我连续运行其中 3 个时,它给出了这个异常
Exception in thread "Thread-8" java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
at java.util.AbstractList$Itr.next(AbstractList.java:343)
at EventManager.run(EventManager.java:77)
at java.lang.Thread.run(Thread.java:662)
Run Code Online (Sandbox Code Playgroud)
这是问题的来源方法:
EventManager.getSingleton().addEvent( new Event() {
public void execute(EventContainer c) {
p.createProjectile(p.absY, p.absX, offsetY, offsetX, 1166, 43, 31, 70, p2.playerId);
c.stop(); // stops the event from running
}
}, 950); // in ms (1 second = 1000 ms)
EventManager.getSingleton().addEvent( new Event() {
public void execute(EventContainer c) {
p2.applyDAMAGE(misc.random(25));
c.stop(); // stops the event from running
}
}, 1300); // in ms (1 second = 1000 …Run Code Online (Sandbox Code Playgroud)