Compiler Error J0127

'else' keyword used without 'if' statement

The compiler detected the keyword else but did not find a corresponding if statement. This error usually occurs when there are scoping issues regarding the placement of an else statement. It can also occur if an else statement's corresponding if statement is missing.

The following example illustrates this error:

public class Simple {
   
   public void method1(int arg1) {
      if (arg1 == 0){
        //Do something here
        else{}
           //error 'else' is inside of the 'if' block instead of outside
      }
   }
}