简体   繁体   English

如何解决非静态方法

[英]How fix Non-static method

this is my code in android studio and I can't fix this 这是我在android studio中的代码,我无法解决此问题 在此处输入图片说明

use alertDialog (ie alertDialog.setTitle("Confirm Box") ) instead of AlertDialog (or however your class is called) and it should work fine..! 使用alertDialog (即alertDialog.setTitle("Confirm Box") )代替AlertDialog (或调用您的类),它应该可以正常工作。

you need to create an instance of a class to be able to call the method properly 您需要创建一个类的实例才能正确调用该方法

(this holds generally in Java - you can only call static methods without creating the object previously..) (这在Java中通常适用-您只能调用静态方法,而无需先前创建对象。)

in your case the method setTitle is not static so you need to call it via the instance you previously created 在您的情况下, setTitle方法不是静态的,因此您需要通过先前创建的实例进行调用

You probably need to create an instance of the AlertDialog writing something like: 您可能需要创建类似以下内容的AlertDialog实例:

AlertDialog alertDialogInstance = alertDialog.build();

then you can call alertDialogInstance.setTitle("title"); 然后您可以调用alertDialogInstance.setTitle("title");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM