Wenn ich versuche, auf die Methode einer anderen Klasse zuzugreifen, gibt es mir einen Fehler, dass nicht statische Methode nicht von statischen Methode zugegriffen werden kann, aber keine meiner Methoden sind statisch.Ich kann nicht auf die acessor-Methode einer anderen Klasse zugreifen? Java
import java.util.ArrayList;
public class creatureClassDriverRathtarsGame
{
public static void main(String[] args)
{
creatureClass player = new creatureClass("name", 14,new locationClass(0, 0, 0));
ArrayList <locationClass> locationRathTars = new <locationClass> ArrayList(5);
for(locationClass r: locationRathTars)
{
int randomRow = (Math.random() * ((locationClass.getMaxRow()) + 1));
int randomCol = (Math.random() * ((locationClass.getMaxCol()) + 1));
creatureClass rathtars = new creatureClass("rathtars",0, new locationClass(randomRow, randomCol, 0));
}
und die acessor Methode, ist
public int getMaxRow()
{
return maxrow;
}
public int getMaxCol()
{
return maxcol;
}
Bitte eine tatsächliche [MCVE] veröffentlichen. So wie es aussieht, nehme ich an, dass Ihre Klasse 'locationClass' heißt und Sie tatsächlich Methoden daraus statisch aufrufen. – CollinD
Die folgenden grundlegenden Java-Code-Konventionen hätten das Problem aufgezeigt. Klassennamen müssen mit einem Großbuchstaben beginnen. Instanz (Objekt) einer Klasse sollte einen Kamelnamen haben. – Slava
Sie rufen locationClass.getMaxRow() auf, wenn Sie r.getMaxRow() aufrufen möchten. – antlersoft