Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"isEmpty() is undefined for the type String" in Eclipse 1.7 compiler? [duplicate]

Possible Duplicate:
Java isEmpty() undefined for String?

I copied my code from one java project to another and I get the error:

The method isEmpty() is undefined for the type String

But the same isEmpty() works perfectly fine for checking string in the original program.

Instead I can use str.length()==0. But wondering what would be the reason for this?

[edit] All of this are done in the same eclipse compiler version 1.7 in the same machine. i.e. Windows -> Preferences -> Java -> Compiler, I find the " Compiler compliance level as 1.7". Including the original program where isEmpty worked and the new program where it is not working.

My another project which has isEmpty works fine. I created a new proj and copied a part of code which has isEmpty and I am getting this error.

like image 494
SyncMaster Avatar asked Dec 16 '22 06:12

SyncMaster


1 Answers

isEmpty is a method from Java 1.6 and your problem is that you've got Eclipse's Java compiler compliance level set < 1.6. The solution is to go into Eclipse's preferences and set the compiler's compliance level to 1.6 or higher.

Menus:

Windows -> Preferences -> Java -> Compiler.

Edit
SyncMaster states in a comment:

... I find the " Compiler compliance level as 1.7".
... I created a new proj and copied a part of code which has isEmpty and I am getting this error

Solution: What I've described above is for the "master" compliance level, but each project can override this. To check the project's compliance level, right-click the project in Eclipse's package explorer, click Properties, then Java Compiler. Then you can decide whether or not to enable project-specific settings and just what those settings should be.

like image 194
Hovercraft Full Of Eels Avatar answered Dec 18 '22 21:12

Hovercraft Full Of Eels