Problem category: Compile-time Problems
Diagnosis Difficulty: Medium
Difficulty to Fix: Easy-medium
The two most common incarnations of this problem are not putting your code inside of the main method, or not putting initializing code inside of a static initializer block or constructor.
Missing main method:
public class Test { int a = 5; for(int i = 0; i < a; ++i) { System.out.println(i); } }
Attempting to perform multi-statement initialization outside of a static initializer block/constructor.
public class Test { public static int[] myArray; myArray = new int[5]; for(int i = 0; i < myArray.length; ++i) { myArray[i] = i * i; } }
Error Messages
Unfortunately, this type of problem doesn't really have any indicative error message. You will probably get tens if not hundreds of error messages of other problems the Java compiler is finding because of this problem.
Suggested fixes
Missing main method: Add a main method
Attempting to perform multi-statement initialization outside of a static initializer block/constructor: add a static initializer block (or a constructor, depending on if you want to initialize static or instance variables).
public class Test { public static int[] myArray; static { myArray = new int[5]; for(int i = 0; i < myArray.length; ++i) { myArray[i] = i * i; } } }