This question already has answers here:
Non-static variable cannot be referenced from a static context
(12个答案)
5年前关闭。
我想访问另一个.Class的返回值。我是否必须将其设置为静态?
例如:
1级被叫玩家
2级
我的错误是无法从播放器类型静态引用非静态方法getRemainingItemUses()
(12个答案)
5年前关闭。
我想访问另一个.Class的返回值。我是否必须将其设置为静态?
例如:
1级被叫玩家
public int getRemainingItemUses(){
return remainingItemUses;
}
2级
Player.getRemainingItemUses()
我的错误是无法从播放器类型静态引用非静态方法getRemainingItemUses()
最佳答案
您可以使getRemainingItemUses()
静态,或创建Class1
的实例并在其上调用方法:
Class1 c = new Class1();
int result = c.getRemainingItemUses();
09-26 10:03