gpt4 book ai didi

java - Joda 和 Java lang 整数不兼容

转载 作者:行者123 更新时间:2023-12-01 17:34:01 24 4
gpt4 key购买 nike

收到此错误:

 incompatible types
required: java.lang.Integer
found: java.util.Map.Entry<org.joda.time.DateTime.java.lang.Integer>

以及导致错误的代码:

public static void checkRange() {

DateTime startx = new DateTime(startDate.getTime());
DateTime endx = new DateTime(endDate.getTime());

//produces submap
Map<DateTime, Integer> nav = map.subMap(startx, endx);

//this is the line causing the error:
for (Integer capacity : map.subMap(startx, endx).entrySet()) {

}
}
}

我之前将 startDate 和 endDate 定义为 Date,然后将它们转换为 DateTime,如您所见。我不认为这是问题所在 map 是

public static TreeMap<DateTime, Integer> map = new TreeMap<DateTime, Integer>();

谢谢

最佳答案

entrySet() 返回映射的“行”,即包含键和值的 Entry 对象。要仅迭代值,您可以使用 map.values(),在本例中它是 Integer 的集合。

关于java - Joda 和 Java lang 整数不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8180249/

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