0

このエラーの取得:

 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()) {

        }
}
}

以前にDateとして定義されたstartDateとendDateを持っていて、DateTimeに見えるようにここで変換します。私はそれが問題だとは思わないし、地図は

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

ありがとう、

4

2 に答える 2

3

は、マップのentrySet()「行」、つまり、Entryキーと値の両方を含むオブジェクトを返します。値だけを反復処理するには、この場合map.values()のコレクションであるを使用できます。Integer

于 2011-11-18T09:29:23.913 に答える
2

map.subMap(startx, endx).values()の代わりに必要なもののようですmap.subMap(startx, endx).entrySet()

于 2011-11-18T09:29:21.137 に答える