Results 1 to 3 of 3
Thread: Syntax error in If statement
- 11-08-2012, 09:52 AM #1
Member
- Join Date
- Jul 2012
- Posts
- 3
- Rep Power
- 0
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
- 11-08-2012, 10:26 AM #2
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
Re: Syntax error in If statement
Syntax of if statement is like
if(condition){
//logic
}else{
//logic
}
No ; is required after if(condition)
- 11-08-2012, 10:38 AM #3
Godlike
- Join Date
- Nov 2012
- Posts
- 195
- Rep Power
- 1
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:
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 :)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) {
Similar Threads
-
the switch statement and unreachable statement error
By name in forum New To JavaReplies: 2Last Post: 03-26-2012, 04:27 PM -
Syntax error in UPDATE statement Need Help!
By mathidioticz in forum New To JavaReplies: 7Last Post: 01-21-2012, 06:48 PM -
Syntax of Switch statement in j2me
By jprgmr75 in forum CLDC and MIDPReplies: 0Last Post: 01-03-2011, 05:49 PM -
Java Syntax If statement
By Blasz in forum New To JavaReplies: 9Last Post: 09-01-2010, 12:21 PM -
syntax error
By gabriel in forum New To JavaReplies: 3Last Post: 08-03-2007, 03:26 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks