-2
当我尝试访问另一个类的方法时,它给了我一个错误,即无法从静态方法访问非静态方法,但我的方法都不是静态方法。我无法访问另一个类的处理器方法? 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));
}
和被称为acessor方法是
public int getMaxRow()
{
return maxrow;
}
public int getMaxCol()
{
return maxcol;
}
请张贴实际[MCVE。现在,我假设你的类被称为'locationClass',你实际上正在静态地调用它的方法。 – CollinD
遵循基本的Java代码惯例会指出问题。类名必须以大写字母开头。一个类的实例(对象)应该有一个骆驼式的名字。 – Slava
当您想要调用r.getMaxRow()时,您正在调用locationClass.getMaxRow() – antlersoft