For a non-static inner class, the compiler automatically adds a hidden reference to an instance of the owner object. When you try to create it from a static method (say, the main method), there is no instance owner. This is similar to trying to call an instance method from a static method - the compiler will not allow it, because in fact you do not have an instance to call.
Thus, the inner class must be either static (in this case no instance is required) or you create an instance of the inner class from a non-static context.
source share