The "illegal start of expression" error in Java can be caused by any one of the following three reasons:
public void foo(){
System.out.println("No closing bracket for this function.");
This has to be resolved manually by looking for a pair of curly brackets for each code block and completing the missing ones.
public void foo(){
// Declaring bar() inside foo():
private int bar(){
return 10;
}
}
Move the function declared inside (i.e., bar()
) to an appropriate place outside the outer function (i.e., foo()
).
private int foo(){
// Writing 'public' with 'int':
public int x = 5;
return x;
}
The local variables of a function are only visible inside it and their scope cannot be widened or narrowed. Remove the access specifiers of the variables to resolve this error.
Free Resources