Cannot make a static reference to the non-static method

后端 未结 7 2145
长发绾君心
长发绾君心 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 05:15

    for others that find this in the search:

    I often get this one when I accidentally call a function using the class name rather than the object name. This typically happens because i give them too similar names : P

    ie:

    MyClass myclass = new MyClass();
    
    // then later
    
    MyClass.someFunction();
    

    This is obviously a static method. (good for somethings) But what i really wanted to do (in most cases was)

    myclass.someFunction();
    

    It's such a silly mistake, but every couple of months, i waste about 30 mins messing with vars in the "MyClass" definitions to work out what im doing wrong when really, its just a typo.

    Funny note: stack overflow highlights the syntax to make the mistake really obvious here.

    0 讨论(0)
提交回复
热议问题