Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By SurfMan

Thread: Syntax error in If statement

  1. #1
    Join Date
    Jul 2012
    Posts
    3
    Rep Power
    0

    Default Syntax error in If statement

    Dear All,

    I am not a JAVA developer and tried to develope a JAVA code to be used in SAP as printed below. So now I got a syntax error and most probably I feel that its the issue with Semi Colon ;

    Below is the piece of code.

    String value = "";
    String actual = "";
    int flag = 0;
    int count = 0;
    int qtnum = 0;
    if (AlertPayload.length() != 0);
    {
    for (int i =0;i<AlertPayload.length();i++);
    {
    if(count == 3);
    {
    if (value.equals("AdapterType"));
    {
    if (AlertPayload.charAt(i) != '"');
    {
    actual = actual + AlertPayload.charAt(i);
    }
    else
    {
    result = actual; flag = 0; count = 0;
    break;
    }
    }
    else
    {
    flag = 0; count = 0; value = "";
    }
    }
    else if(flag ==1 && count != 3)
    {
    if(AlertPayload.charAt(i) != '"' && qtnum != 4);
    {
    value = value + AlertPayload.charAt(i);
    }
    else
    {
    flag = 0; count = count +1; qtnum = qtnum + 1;
    if (qtnum == 5);
    {
    qtnum = 0;count = 0;
    }
    }
    }
    else if(AlertPayload.charAt(i) == '"')
    {
    flag = 1;
    count = count +1;
    qtnum = qtnum + 1;
    }
    }
    }
    //result = value;
    return result;


    The error I receive while compiling is

    Function Component, Line 18:
    'else' without 'if'
    else
    ^
    Function Component, Line 24:
    'else' without 'if'
    else
    ^
    Function Component, Line 29:
    'else' without 'if'
    else if(flag ==1 && count != 3)
    ^
    Function Component, Line 35:
    'else' without 'if'
    else
    ^
    4 errors


    Have any suggestions , please post.

    Regards
    RST

  2. #2
    abhijiths is offline Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Default Re: Syntax error in If statement

    Syntax of if statement is like

    if(condition){
    //logic
    }else{
    //logic
    }
    No ; is required after if(condition)

  3. #3
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,030
    Rep Power
    4

    Default Re: Syntax error in If statement

    You are adding all semicolons after each for-statment and if-statement. That means the for and if statements end there and no looping and testing is done. Remove all the semicolons after for and if so it becomes like the example below:

    WRONG:
    Java Code:
    if (AlertPayload.length() != 0) ;
    {
      for (int i = 0; i < AlertPayload.length(); i++) ;
      {
         if (count == 3) ;
         {
    RIGHT:
    Java Code:
    if (AlertPayload.length() != 0) 
    {
      for (int i = 0; i < AlertPayload.length(); i++) 
      {
         if (count == 3) 
         {
    To make it more readable, I always place the curly braces *behind* the if/for etc like the example below, but that is a highly debated subject and I am not responsible for any flamewars/trolling that will come from this :)

    RIGHT:
    Java Code:
    if (AlertPayload.length() != 0) {
      for (int i = 0; i < AlertPayload.length(); i++) {
         if (count == 3) {

Similar Threads

  1. Replies: 2
    Last Post: 03-26-2012, 05:27 PM
  2. Syntax error in UPDATE statement Need Help!
    By mathidioticz in forum New To Java
    Replies: 7
    Last Post: 01-21-2012, 07:48 PM
  3. Syntax of Switch statement in j2me
    By jprgmr75 in forum CLDC and MIDP
    Replies: 0
    Last Post: 01-03-2011, 06:49 PM
  4. Java Syntax If statement
    By Blasz in forum New To Java
    Replies: 9
    Last Post: 09-01-2010, 01:21 PM
  5. syntax error
    By gabriel in forum New To Java
    Replies: 3
    Last Post: 08-03-2007, 04: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
  •