Must qualify the allocation with

Ok Thank u, I got it!

Thank u too for mini correction!

@quark @GoToLoop there is a possibility that you can answer also at my other question in this post?
Because I missing something. Of course If you know stuff about Neural Network :smiley:
Thank you anyway for the appreciated help!

Given that the error message that @Manatee is seeing (“Must qualify the allocation …”) is caused by not using an inner class, I’m not sure describing less “fudgy” ways to write code that still won’t work is that useful! :wink:

In the example posted earlier with Snake and Jumble (which I assume should be Jungle?! :smile:), a static Jumble class cannot create a Snake class like that. An inner class has one hidden extra field than a normal class, which is a reference to the enclosing instance - in this case the instance of PApplet. In effect, whenever you create a Snake inside PApplet your call to new Snake() is translated to something like new Snake(this).

Your Jumble class, if it had a reference to a PApplet, could create a Snake using -

PApplet applet;
Snake snake = Snake();

I had to look that syntax up - it’s there but not something you see very often.

In general, just use inner classes and stop fighting with the type system. If you really want static classes, make them all static and pass the PApplet into them. Don’t have static classes referring to inner classes or you’ll end up in a mess!


Problem solved :smiley: Dont worry

Ok ok, no problem. I will not use instance method at this point, or I will get with a super messy code!
Anyway is Jumble synonymous of a lot of people/stuff/things

1 Like

My research shows that the “Must qualify the allocation…” message is created when trying to instantiate an inner class without qualifying it with an object of the outer class.

If the sole reason of making an inner class static is to make it behave like a top-level class then it is fudgy or more accurately, bad programming practice. The code I presented was not meant to be a solution to his code (we don’t have it all), it simply shows how to create a true top-level class which he could adapt to his own use.

OK I know this is not technically true :grinning: but the whole truth can be confusing :thinking:. For decades it has been good programming practice to name the Java source file after the class. One reason is that It makes it easier to debug large projects.

We don’t teach the truth, we teach what the learner can comprehend.
Quark 2018 :grinning:


Alright! However, avoid using absolute verbs like must, have to, ought to. :unamused:

Go w/ something like should or need to instead. :innocent:

1 Like

Well, yes if you want it to compile! :smile: Although you learn something new every day - never realised it only applied to public classes - and my Java experience is in the decades.

Sorry my mistake, I meant to use the following in my example

public class Population {

in which case it must be in its own file ‘’