Cannot make a static reference to the non-static method

后端 未结 7 2127
长发绾君心
长发绾君心 2020-11-21 04:32

Building a multi-language application in Java. Getting an error when inserting String value from R.string resource XML file:

public static final         


        
7条回答
  •  长情又很酷
    2020-11-21 04:54

    getText is a member of the your Activity so it must be called when "this" exists. Your static variable is initialized when your class is loaded before your Activity is created.

    Since you want the variable to be initialized from a Resource string then it cannot be static. If you want it to be static you can initialize it with the String value.

提交回复
热议问题