This is going well outside the scope of a "beginner" discussion, but I want to present an accurate picture here. The beginner answer to Fitz's original question is "because the compiler won't let you" - if you want to know why the compiler won't let you, well, read on, but don't say you weren't warned.
[MM]: To instantiate an inner class, there must be an instance of the enclosing class. Not true - it is entirely possible to declare an inner class in a static context, in which case there is no enclosing instance. See
JLS 8.1.2: "An instance of an inner class I whose declaration occurs in a static context has no lexically enclosing instances." Or try to compile the following:
Even in a static context, an inner class is still not allowed to declare any static members. I think the reason for this is to avoid confusion. Realize that any inner class in a static context is either a local class or an anonymous class. (If it were a member class, it's either static or it isn't; there's no "static context" gray area here.) Consider a local class defined inside a static method, as above. Looking at the code, you may think this class comes into existence when the method is executed, and is subsequently forgotten and eligible for GC after the method completes. (Behind the scenes that's not really what happens, but it's a reasonable guess for something declared locally.) If I execute the method twice, should I get the same inner class the second time, or a different one? That is, if the class had some static member data which is modified during execution of the method, when I run the method a second time, should I see the changed static data, or should it be re-initialized? The answer isn't really clear, IMO. The JLS could have defined an answer, but I believe many programmers would remain very confused over the issue, and this would be a recurring source of bugs. Instead the JLS simply forbids static members of local and anonymous classes, to avoid this confusion.
There are similar issues for nonstatic member classes. If you have two different outer class instances, and each has one or more inner class instances associated with it, and those inner classes had "static" data, should the data be shared among
all inner instances, or only those associated with the same outer instance? Again, it's too confusing, so
Java's designers chose to simply forbid it. If there's some static state info you need to keep track of, put it somewhere in the outer class; don't try to attach it to an inner class.