java - Android - 明明实例化并使用了对象,但是Android Studio提示并没有使用对象
PHP中文网
PHP中文网 2017-04-17 16:59:18
0
5
486
PHP中文网
PHP中文网

认证0级讲师

reply all(5)
Peter_Zhu

It reminds you that the place where this thing is referenced is only in one method (that is, in onCreate), and other methods and external classes do not reference it.
So, you can turn it into a temporary variable and put it in that method.
According to your situation, Android Studio wants you to put this variable in onCreate and does not need to be a member variable of Activity.
Generally speaking, I usually hold things like this View as member variables instead of temporary variables. For the sake of code consistency, if I want to adjust the properties of the View one day, I don’t need to declare it as a member variable again. Okay trouble.

PHPzhong

Try re-importing the R file

迷茫

It means that you can make it a member variable~or if you write a method and use it, there will be no warning

洪涛

Because although you assigned a value to it, you have not used this private variable.

洪涛

The subject’s understanding of the question needs to be improved...

The prompt means that these members are declared but not used. The lines in create only assign values ​​to the members, which is not called use. The reason why the button does not prompt is because the setonclicklistener method is accessed and called later, which is called use.
As for textview, it should be accessed elsewhere. The screenshot code snippet is limited and I can’t see where it is called

In addition, the statement "newly created and instantiated" in the question seems to be a pain in the ass. It only holds a reference to a view that has been automatically instantiated through assignment...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template