2011-11-18 38 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()