Results 1 to 8 of 8
  1. #1
    romilc is offline Member
    Join Date
    Oct 2009
    Posts
    3
    Rep Power
    0

    Default Syntax error on token "(", ; expected

    Eclipse is showing this error...
    Code:
    Syntax error on token "(", ; expected
    Syntax error on token ")", ; expected
    line 11 and 15..

    the following is my code:
    import javax.jws.WebService;

    @WebService
    public class try2
    {
    String num1,num2;
    public try2(){}
    public String getNmbers()
    {

    final String getNumber1(String num1)
    {
    return num1;
    }
    final String getNumber2(String num2)
    {
    return num2;
    }
    }
    }

    please help me solving the errors in the above code..

  2. #2
    toymachiner62 is offline Member
    Join Date
    Oct 2009
    Posts
    63
    Rep Power
    0

    Default

    Java Code:
    import javax.jws.WebService;
    
    @WebService
    public class try2 
    {
        String num1,num2;
        public try2(){}  
        public String getNmbers()
        {
    
            final String getNumber1(String num1)
            {
                return num1;
            }
            final String getNumber2(String num2)
            {
                return num2;
            }
        }
    }
    It's because your declaring 2 methods inside of getNumbers()

  3. #3
    romilc is offline Member
    Join Date
    Oct 2009
    Posts
    3
    Rep Power
    0

    Default

    ok..
    so but what shud i do then..
    as i want both the values num1 n num2 by calling a single method

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    A method can only return one value. You could bundle the two values into a class and return an object of that class containing the two values.

    P.S It is better to read and understand these basics of Java before trying to write webservices. You will just program yourself into a corner if you don't know them.

  5. #5
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    6

    Default

    Java Code:
    import javax.jws.WebService;
    
    @WebService
    public class try2 
    {
        String num1,num2;
        public try2(){}  
        public String getNmbers()
        {
    
            final String getNumber1(String num1)
            {
                return num1;
            }
            final String getNumber2(String num2)
            {
                return num2;
            }
        }
    }
    well the way you did it can be done when you are using loops but methods are like definitions of the program functions .

    btw
    Java Code:
    import javax.jws.WebService;
    why is that line present?

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Quote Originally Posted by [RaIdEn] View Post
    Java Code:
    import javax.jws.WebService;
    
    @WebService
    public class try2 
    {
        String num1,num2;
        public try2(){}  
        public String getNmbers()
        {
    
            final String getNumber1(String num1)
            {
                return num1;
            }
            final String getNumber2(String num2)
            {
                return num2;
            }
        }
    }
    well the way you did it can be done when you are using loops but methods are like definitions of the program functions .

    btw
    Java Code:
    import javax.jws.WebService;
    why is that line present?
    Even with loops you still can't return two values from a method.
    The import is required because of the @WebService annotation on the class.

  7. #7
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    6

    Default

    Quote Originally Posted by r035198x View Post
    Even with loops you still can't return two values from a method.
    The import is required because of the @WebService annotation on the class.
    yes your rite you cannot return 2 values. I also agree with that. I was just

    talking on general terms.

  8. #8
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    6

    Default

    for example, i'll give you an example.

    Java Code:
    public class demo
    {
    
           int numbers(int n)
          {
                 n++;
                 return n; 
    
                //--This is where JVM stops. Because of the return statement, it exits the method
                 n--;
                return n;
           }
    }
    Last edited by [RaIdEn]; 10-24-2009 at 02:25 AM.

Similar Threads

  1. Syntax error on token "(", ; expected
    By baltimore in forum AWT / Swing
    Replies: 3
    Last Post: 10-28-2009, 01:19 AM
  2. Replies: 3
    Last Post: 05-21-2009, 04:48 PM
  3. Unfamiliar Syntax "int x = i1 << 24 | i2 ..."
    By KentDMc in forum New To Java
    Replies: 5
    Last Post: 04-11-2009, 04:21 AM
  4. Replies: 3
    Last Post: 12-05-2008, 09:34 PM
  5. Replies: 1
    Last Post: 10-20-2008, 08:35 AM

Posting Permissions

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