I am getting a compiling error for this code:
public class Matching {
public static int match = (int) Math.floor(Math.random()*cities.size()); //Error is here
}
I'm want to make "match" a global variable.
My compiling error is:
"Illegal static declaration in inner class testingProgram.Matching modifier 'static' is only allowed in constant variable declarations
Usage of static non-final variable during initialization."
Don't know what the error means, nor do I know how to fix it.
This happens because your Matching
class is located inside another class called testingProgram
, and is not static
.
Java allows static
fields inside an inner class only when the inner class itself is static
. You can fix this problem in several ways:
Matching
a static
inner class,Matching
a top-level class, orstatic int match
final, i.e. final static int match