Firstly, I know this question has already been answered, however, I've looked through all the answers I could find and none of them helped.
I'm making a game in LibGDX, to simulate physics with large pixels. To create the different kinds of pixels, I've decided to make classes inside my Types
class, empty space will also be a kind of pixel which I'll render as black, so I have a class within Types
called None
, which will be used for emptiness.
In my Main
class, I create an ArrayList which contains ArrayLists which contains instances of Types
:
public ArrayList<ArrayList<Types>> grid;
...
for (int y = 0; y < 151; y++) {
ArrayList<Types> row = new ArrayList<Types>();
for (int x = 0; x < 105; x++) {
row.add(Types.None);
}
grid.add(row);
}
And, my Types class looks like this:
package io.j4cobgarby.github;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
public class Types {
public static Types None = new None();
public float mass;
public Color colour;
public boolean dynamic;
public boolean conducts_electrons;
public float conducts_heat;
public Types(float mass, Color colour, boolean dynamic, boolean conducts_electrons, float conducts_heat) {
this.mass = mass;
this.colour = colour;
this.dynamic = dynamic;
this.conducts_electrons = conducts_electrons;
this.conducts_heat = conducts_heat;
}
public void getInput() {
}
public void dynamUpdate() {
}
public void staticUpdate() {
}
public void delete() {
}
public class None extends Types {
public None() {
super(0.0f, Color.BLACK, false, false, 0.0f);
}
@Override
public void getInput () {
if (Gdx.input.isKeyJustPressed(Keys.T)) {
System.out.println("T pressed");
}
}
}
}
So what I hopes was that I would now have an ArrayList containing 151 other ArrayLists, each containing 105 instances of Types.None
But, this doesn't work.
On line 10 of Types
- public static Types None = new None();
- I get this error:
No enclosing instance of type Types is accessible. Must qualify the allocation with an enclosing instance of type Types (e.g. x.new A() where x is an instance of Types).
Why is this? I've tried many things, but I can't seem to get it working.
Thanks.