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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With