Results 1 to 9 of 9
  1. #1
    new_2_java is offline Member
    Join Date
    Feb 2008
    Posts
    60
    Rep Power
    0

    Default why String.isEmpty() gives syntax error

    Hello all,

    I am using EWS Java API, and in eclipse it gives syntax errors on all occurance of :

    String.isEmpty()

    complaining about isEmpty() not recognized.


    Can someone please help me understand why it complains about this? Does it have to do anything with the version of compiler that I have for my eclipse? Please advise...


    Thanks.

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default

    You should not be using the class name "String.isEmpty()"

    You should be using the string variable name "myString.isEmpty()"

    Also, the isEmpty() method was added in JDK1.6. Check your version of the JDK.

  3. #3
    new_2_java is offline Member
    Join Date
    Feb 2008
    Posts
    60
    Rep Power
    0

    Default

    I am actually using myString.isEmpty();

    I downloaded JRe6, and changed my eclipse setting to use JRE6. Recompiled, and now I am getting the following error:


    java.lang.UnsupportedClassVersionError: Bad version number in .class file
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :620)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader .java:260)
    at java.net.URLClassLoader.access$100(URLClassLoader. java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:268)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 51)
    at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:319)
    Exception in thread "main"



    Please help.

  4. #4
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    this error occurs when you try to run a class that is
    - compiled with a newer version of java
    - run with an older version of JVM

    you may have installed the latest version but newer versions get stored into different paths e.g.
    C:/Program Files/Java 1.6.0
    C:/Program Files/Java 1.5.0

    even if you uninstalled the older version it only deletes the older path, but the fact remains you will still need to update your CLASSPATH in the system so that when you run the command:

    javac something.java
    java something

    the system selects the correct installation of JAVAC.exe and JAVA.exe

  5. #5
    new_2_java is offline Member
    Join Date
    Feb 2008
    Posts
    60
    Rep Power
    0

    Default

    I agree with you.

    Let me give you abit more background:

    I am trying to use EWS Java API to simply connect to an exchange server.

    The package that I am using is microsoft.exchange.webservices.data

    My eclipse is using compiler version of 1.5 and JRE is 1.5.0_12

    How can I find out that classes in that particular package is compiled with which version?

    I can also see a lot of occurances of String.isEmpty(). I suspect that isEmpty() has been introduced in Java 6?

    So, can you tell me which version of java will I need? how to resolve this error?

  6. #6
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    uninstall all versions of java runtime environment and java SDK you have, download the latest versions, install them, set your CLASSPATH correctly to run the latest version of java.exe and javac.exe

    as for String.isEmpty() or any other built-in method, you can check those in the Java API specification, a simple google search will help you. i've done it this time for you:

    String (Java Platform SE 6)

    from the above link look down the list and click on "isEmpty()"

    immediately we see it says:
    Since:
    1.6

    and 1.6 = java 6, therefore not compatible with 1.5 (java 5)


    hope this helps..
    Last edited by ozzyman; 03-25-2011 at 10:01 PM.

  7. #7
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default

    I suspect that isEmpty() has been introduced in Java 6?
    What do you mean suspect? I already told you that!

  8. #8
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    lol... fight fight fight fight!

    no i'm joking. he probably forgot since he had a different error to deal with after that.

  9. #9
    new_2_java is offline Member
    Join Date
    Feb 2008
    Posts
    60
    Rep Power
    0

    Default

    @camickr:

    Sorry dude. I know you mentioned that. And I have to agree with you.

    I am getting a different error, and I kind of thought to first resolve this version issue first, then that might in essence resolve String.isEmpty() issue.

    I will try your suggestion, ozzyman. I will install brand new JDK 6 + JRE 6 (I have a VM on my laptop, so i don't mess up my host OS), and will setup my eclipse, and test from there. I will update this thread as well.

    look forward for more questions, sometimes next week.

    TTYL.

Similar Threads

  1. javadb syntax error
    By ron2794 in forum JDBC
    Replies: 9
    Last Post: 01-06-2011, 03:21 PM
  2. sql select ,error in your SQL syntax
    By miko5054 in forum JDBC
    Replies: 13
    Last Post: 06-28-2010, 11:48 AM
  3. No more syntax error
    By ideyatech in forum Java Software
    Replies: 2
    Last Post: 04-22-2010, 04:20 AM
  4. Replies: 6
    Last Post: 04-09-2009, 01:50 PM
  5. syntax error
    By gabriel in forum New To Java
    Replies: 3
    Last Post: 08-03-2007, 03:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •