views:

3432

answers:

4

I'm working on a school project in eclipse, and when I try and use the isEmpty() method on a String, Eclipse shows up the following error:

"The method isEmpty() is undefined for the type String"

I've run the Java updates, but am still getting it. Is any reason why this method would be undefined?

+1  A: 

According to http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html there's no method isEmpty() for java.lang.String in Java 1.5, but in Java 1.6.

java -version

can tell you which version you really have.

VolkerK
+4  A: 

String.isEmpty() was introduced in Java release 1.6. You might want to check what JDK version you're using for your project. (I don't know much about Eclipse myself, but it should be somewhere in the project settings.)

Jonik
great, thanks! I've just had a look and I'm on 1.5, even though I ran the lastets OSX java update, which is supposed to update to Java SE 6 version 1.6.0_05.
Aaron Moodie
Check if you can get 1.6 added in Ecplise's "Installed JREs" as illustrated in Rich Seller's answer :)
Jonik
@Aaron you pretty much have to manually change the `CurrentJDK` sym-link (located in `/System/Library/Frameworks/JavaVM.framework/Versions`) to point at 1.6 instead of 1.5 if you want 1.6 as your default JDK.
Hank Gay
+12  A: 
Rich Seller
As this is a beginner question, perhaps it should be explicitly mentioned that that the StringUtils class is from a 3rd-party open-source library, Apache Commons Lang (http://commons.apache.org/lang/)
Jonik
@Jonik, good point, added
Rich Seller
thanks guys, got it working.
Aaron Moodie
hey Jonik, sorry, one more question. i've got 1.6 working, but am now getting this error: ZoneInfo: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/zi/ZoneInfoMappings (No such file or directory) Is there something else in Eclipse I need to change?
Aaron Moodie
Rich Seller
+1  A: 

If you're not on Java 6, String.length() == 0 will return the same result as String.isEmpty().

dogbane