0

目前,我正在尝试让几种方法相互访问。但是,我收到了一个我无法弄清楚的错误。

这是我得到的错误:

无法从类型 teaminfo 对非静态方法 acceptadd(String) 进行静态引用

我查看了一个方法或变量在不应该是静态的时候是否是静态的,但是方法 acceptadd(String) 或我从中调用它的方法都不是静态的。我不知道如何解决这一点,有人可以帮助我吗?

这是我的 GuiAddReject 代码:

http://pastebin.com/Yj1Ny5Pz

错误无法从类型 teaminfo 对非静态方法 acceptadd(String) 进行静态引用位于此行:

        teaminfo.acceptadd(playername);

这是teaminfo.java:

http://pastebin.com/NxM8rwrE

任何帮助,将不胜感激。

另外,对链接感到抱歉,无法使代码括号起作用...

4

2 回答 2

2

The problem is that you're trying to call an instance method as if it were static.

On the line that you cited:

teaminfo.acceptadd(playername);

teaminfo is a class name, not a variable referring to an instance of that class. You want to create a teaminfo object somewhere in your project, e.g. in GuiAddReject, and call the methods on that object.

于 2012-06-10T17:44:28.977 回答
0

The error means that you are trying to access a non-static method (acceptadd) from a static context (i.e. not from an object). To solve this you need to make an object of the class to which the method you want to call belongs and call the method from its reference.

for example the correct way would be:

teaminfo tf = new teaminfo();
tf.acceptadd(playername);
于 2012-06-10T17:45:15.047 回答