2011-11-18 21 views
0

收到此错误:整数不相容乔达和Java郎

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和结束日期定义为日期较早的话,我在这里将其转换为u可以看到DateTime。我不认为这就是问题所在 和地图是

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

感谢,

回答

3

entrySet()返回地图的“行”,即包含它们的键和值的Entry对象。要遍历这些值,可以使用map.values(),在这种情况下,它是Integer的集合。

+0

辉煌:D错误已经过去非常感谢...以及我没有清楚知道的好解释 –

2

好像你想要的是map.subMap(startx, endx).values(),而不是map.subMap(startx, endx).entrySet()