简体   繁体   English

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

[英]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.

相关问题 获取错误“无法对类型为Intent的非静态方法putExtra(String,String)进行静态引用” - Getting error “Cannot make a static reference to the non-static method putExtra(String, String) from the type Intent” 无法从类型XHTMLImporter静态引用非静态方法setHyperlinkStyle(String) - Cannot make a static reference to the non-static method setHyperlinkStyle(String) from the type XHTMLImporter 无法从DialogFragment类型静态引用非静态方法show(FragmentManager,String) - Cannot make a static reference to the non-static method show(FragmentManager, String) from the type DialogFragment 类型无法从类型View静态引用非静态方法setVisibility(int) - Type Cannot make a static reference to the non-static method setVisibility(int) from the type View 无法解析webView且无法从Activity类型静态引用非静态方法findViewById(int) - webView cannot be resolved & cannot make a static reference to the non-static method findViewById(int) from the type Activity 错误:“无法从类型Activity中对非静态方法startActivity(Intent)进行静态引用” - Error: “Cannot make a static reference to the non-static method startActivity(Intent) from the type Activity” 无法从类型Cmd对非静态方法getVideoURL()进行静态引用 - Cannot make a static reference to the non-static method getVideoURL() from the type Cmd 无法从View MainActivity.java类型静态引用非静态方法invalidate() - Cannot make a static reference to the non-static method invalidate() from the type View MainActivity.java Java - 无法从类型“something”中对非静态方法“something”进行静态引用 - Java - Cannot make a static reference to the non-static method "something" from the type "something" 无法使 static 引用非静态方法 --- 从类型 --- Java Bukkit Minecraft - Cannot make a static reference to the non-static method --- from the type --- Java Bukkit Minecraft
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM