[英]Cannot make a static reference to the non-static method acceptadd(String) from the type teaminfo
Currently, I am trying to make a couple of methods access each other. 目前,我正在尝试使用几种方法相互访问。 However, I am getting an error that I have not been able to figure out.
但是,我收到的错误是我无法弄清楚的。
This is the error I get: 这是我得到的错误:
Cannot make a static reference to the non-static method acceptadd(String) from the type teaminfo 无法从类型teaminfo对非静态方法acceptadd(String)进行静态引用
I looked to see if a method or a variable was static when it was not supposed to be, but neither the method acceptadd(String) or the method I am calling it from is static. 我查看一个方法或变量是否是静态的,当它不应该是,但是方法acceptadd(String)或我调用它的方法都不是静态的。 I have no idea on how to fix it on this point, can someone help me?
我不知道如何在这一点上解决它,有人可以帮助我吗?
Here's my code for GuiAddReject: 这是我的GuiAddReject代码:
http://pastebin.com/Yj1Ny5Pz http://pastebin.com/Yj1Ny5Pz
The error Cannot make a static reference to the non-static method acceptadd(String) from the type teaminfo is at this line: 错误无法对teaminfo类型中的非静态方法acceptadd(String)进行静态引用,如下所示:
teaminfo.acceptadd(playername);
Here is teaminfo.java: 这是teaminfo.java:
http://pastebin.com/NxM8rwrE http://pastebin.com/NxM8rwrE
Any help would be appreciated. 任何帮助,将不胜感激。
Also, sorry about the links, couldn't get the code brackets to work... 此外,抱歉链接,无法让代码括号工作...
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. teaminfo
是一个类名,而不是一个引用该类实例的变量。 You want to create a teaminfo object somewhere in your project, eg in GuiAddReject, and call the methods on that object. 您想在项目的某个位置创建一个teaminfo对象,例如在GuiAddReject中,并调用该对象上的方法。
The error means that you are trying to access a non-static method ( acceptadd
) from a static context (ie not from an object). 该错误意味着您尝试从静态上下文(即不是来自对象)访问非静态方法(
acceptadd
)。 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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.