Showing posts with label Expression. Show all posts
Showing posts with label Expression. Show all posts

Friday, October 30, 2009

Published 10/30/2009 by with 7 comments

illegal initializer

You may see this error for writing wrong expression to initialize an array. See the code below: int data={42,15,27,20,19}; If you compile this, you will see the following error message: illegal initializer for intint data={42,15,27,20,19}; ^ Here the array is not declared properly as we have not put [ ] for declaring the array. The correct code is: int data[ ]={42,15,27,20,19}; or int[ ]...
Read More
    email this       edit
Published 10/30/2009 by with 1 comment

incompatible types

1. Sometimes we may get the following error message in an 'if' (selection) structure. incompatible typesfound : intrequired: boolean This is because, we have not specified a boolean expression as the condition of the 'if'; instead we might have written such an expression which is may be int, float, String or other types but not boolean. See the code below: int a=10,b=10; if(a=b){ System.out.println("a...
Read More
    email this       edit

Sunday, May 17, 2009

Published 5/17/2009 by with 0 comment

illegal start of expression

If a method is defined inside another method we may see ‘illegal start of expression’ error message. Remember that, we cannot define a method inside another method; we just can call a method inside another method. Sometimes it occurs just because of improper opening and closing of curly braces ( { or } ). See the following example code: public class IllegalStartOfExpression { public void methodA() { System.out.println("This...
Read More
    email this       edit
Published 5/17/2009 by with 2 comments

identifier expected

This error message is shown when the statements are not written in proper place. Most often, mistakenly, we may write the processing task (for example assigning value to a variable; writing a loop etc.) outside of any method. In this situation we may see this type of error message. Then the solution is to write such statements inside the appropriate methods. See the example code below: public class...
Read More
    email this       edit

Tuesday, November 4, 2008

Published 11/04/2008 by with 0 comment

; (semi-colon) expected

Each java statement must ends with ; (semicolon) in Java. If we don’t put ; after any statement we will see ‘;’ expected Here is an example of this error: public class SemicolonExpected { public static void main(String args[]) { int x=10,y=10 //no ; (semicolon) is given after this statement if(x==y) System.out.println(x +" and "+y+" is equal"); } } Here no ; (semicolon) is given after the x,y...
Read More
    email this       edit