# Must qualify the allocation with

**URL:** https://discourse.processing.org/t/must-qualify-the-allocation-with/2828
**Category:** Coding Questions
**Created:** [August 22, 2018, 12:10am UTC](https://discourse.processing.org/t/must-qualify-the-allocation-with/2828 "2018-08-22T00:10:17Z")
**Posts on this page:** 10
**Page:** 2

<div class="post-metadata">

### Author: ![Manatee](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@Manatee](https://discourse.processing.org/u/Manatee)
#### Post date: [August 23, 2018, 10:03am UTC](https://discourse.processing.org/t/must-qualify-the-allocation-with/2828/21 "2018-08-23T10:03:27Z")

</div>

Ok Thank u, I got it!

---

<div class="post-metadata">

### Author: ![Manatee](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@Manatee](https://discourse.processing.org/u/Manatee)
#### Post date: [August 23, 2018, 10:03am UTC](https://discourse.processing.org/t/must-qualify-the-allocation-with/2828/22 "2018-08-23T10:03:42Z")

</div>

Thank u too for mini correction!

---

<div class="post-metadata">

### Author: ![Manatee](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@Manatee](https://discourse.processing.org/u/Manatee)
#### Post date: [August 23, 2018, 10:05am UTC](https://discourse.processing.org/t/must-qualify-the-allocation-with/2828/23 "2018-08-23T10:05:42Z")

</div>

@quark @GoToLoop there is a possibility that you can answer also at my other question in this post?  
[https://discourse.processing.org/t/neural-network-help/2871](https://discourse.processing.org/t/neural-network-help/2871)  
Because I missing something. Of course If you know stuff about Neural Network 😃  
Thank you anyway for the appreciated help!

---

<div class="post-metadata">

### Author: ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)
#### Post date: [August 23, 2018, 10:29am UTC](https://discourse.processing.org/t/must-qualify-the-allocation-with/2828/24 "2018-08-23T10:29:11Z")

</div>

> [@quark](#):
>
> The main problem is that any class defined in the main window is treated as an _Inner Class_ , one way to make it a top level class is to declare it as static. This is a _ **fudge** _ and generally should be avoided.

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! 😉

In the example posted earlier with `Snake` and `Jumble` (which I assume should be Jungle?! 😄), 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 -

```java
PApplet applet;
Snake snake = applet.new 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!

---

<div class="post-metadata">

### Author: ![Manatee](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@Manatee](https://discourse.processing.org/u/Manatee)
#### Post date: [August 23, 2018, 10:45am UTC](https://discourse.processing.org/t/must-qualify-the-allocation-with/2828/25 "2018-08-23T10:45:07Z")

</div>

Problem solved 😃 Dont worry

---

<div class="post-metadata">

### Author: ![Manatee](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@Manatee](https://discourse.processing.org/u/Manatee)
#### Post date: [August 23, 2018, 10:47am UTC](https://discourse.processing.org/t/must-qualify-the-allocation-with/2828/26 "2018-08-23T10:47:23Z")

</div>

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

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [August 23, 2018, 2:08pm UTC](https://discourse.processing.org/t/must-qualify-the-allocation-with/2828/27 "2018-08-23T14:08:52Z")

</div>

> [@neilcsmith](#):
>
> 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!

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.

> [@quark](#):
>
> the tab name must be exactly the same as the class name including case followed by “ `.java` ” otherwise it won’t work.

OK I know this is not technically true 😀 but the whole truth can be confusing 🤔. 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 😀

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [August 23, 2018, 2:15pm UTC](https://discourse.processing.org/t/must-qualify-the-allocation-with/2828/28 "2018-08-23T14:15:25Z")

</div>

> [@quark](#):
>
> We don’t teach the truth, we teach what the learner can comprehend.

Alright! However, avoid using absolute verbs like `must`, `have to`, `ought to`. 😒

Go w/ something like `should` or `need to` instead. 😇

---

<div class="post-metadata">

### Author: ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)
#### Post date: [August 23, 2018, 2:40pm UTC](https://discourse.processing.org/t/must-qualify-the-allocation-with/2828/29 "2018-08-23T14:40:44Z")

</div>

> [@quark](#):
>
> OK I know this is not technically true … For decades it has been good programming practice to name the Java source file after the class.

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

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [August 23, 2018, 3:42pm UTC](https://discourse.processing.org/t/must-qualify-the-allocation-with/2828/30 "2018-08-23T15:42:31Z")

</div>

> [@quark](#):
>
> class Population {

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

```auto
public class Population {

```

in which case it must be in its own file ‘Population.java’

[Previous page](https://discourse.processing.org/t/must-qualify-the-allocation-with/2828.md?page=1)
