以前にやったことがあると確信しているので、これはかなり簡単だと思いましたが、これを機能させることはできません。私のクラスは:
public class City
{
String start = null;
String end = null;
int weight = 0;
}
そして私はやっています:
City cityGraph[] = new City[l];
たとえば、cityGraph[x].start にアクセスしようとすると、null ポインター例外が発生するため、配列内のすべての要素も初期化する必要があると考えたので、次のようにします。
for(int j = 0; j < l; j++)
{
cityGraph[j] = new City();
}
しかし、それは私にこのエラーを与えています:
No enclosing instance of type Graphs is accessible.
Must qualify the allocation with an enclosing instance
of type Graphs (e.g. x.new A() where x is an instance of Graphs).
これが何を意味するのか、またはそれを修正する方法がわかりません。どんな助けでも大歓迎です!