的封闭实例的分配首先,我知道这个问题已经被回答,但是,我查看了所有可以找到的答案,而且都没有帮助。'必须限定类型为'
我在LibGDX中制作游戏,模拟大像素物理。为了创建不同类型的像素,我决定在我的Types
类中创建类,空白空间也将是一种像素,我将渲染为黑色,所以我有一个Types
之间的类,名为None
,这将是用于空虚。
在我Main
类,我创建一个包含其中包含的Types
实例的ArrayList的ArrayList:
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);
}
而且,我的类型类看起来是这样的:
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");
}
}
}
}
所以,我希望是我现在有一个包含151个ArrayList的ArrayList,每个ArrayList包含105个实例Types.None
但是,这不起作用。
论Types
线10 - public static Types None = new None();
- 我得到这个错误:
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).
这是为什么?我尝试了很多东西,但我似乎无法让它工作。
谢谢。
[爪哇 - 类型的无封闭情况foo是接近]的可能的复制(http://stackoverflow.com/questions/9560600/java-no-enclosing-instance-of-type-foo-is-可访问) – fabian