views:

205

answers:

1

I'm trying to use ceilingKey(), ceilingEntry(), firstKey() and firstEntry() of the TreeMap class but getting error:
java.lang.NoSuchMethodError: method java.util.TreeMap.firstEntry with signature ()Ljava.util.Map$Entry; was not found.

This error is caused by following code:
if (tmpmap.size() == 1 && tmpmap.firstKey() == req_sbyte && tmpmap.firstEntry().getValue() == req_size) {
send("F" + req_nr + "," + Integer.toString(req_filenr) + "," + Long.toString(req_sbyte) + "," + Integer.toString(req_size), "localhost", CLIENTPORT);
}

This is the output of java -version:
java version "1.5.0" gij (GNU libgcj) version 4.1.2 20070925 (Red Hat 4.1.2-33) Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Any explanations why is this happening and how to fix it? I checked libgcj's documentation, and it says there is such method firstEntry() and it returns Entry object which has getValue() method. So I do not clearly understand what is the problem with my code.

+6  A: 

firstEntry() is a Java 1.6 method.

See http://java.sun.com/javase/6/docs/api/java/util/TreeMap.html#firstEntry%28%29.

Joel Carranza
Thanks. I will try to update GIJ. Otherwise I will have install Sun Java...
Azimuth
Yep, it's part of the `NavigableMap` interface that was added in Java 6.
erickson