NoSuchFieldError Java

后端 未结 7 1100
盖世英雄少女心
盖世英雄少女心 2020-11-29 03:44

I am getting a NoSuchFieldError in my code, now oracle isn\'t very clear about why this error is thrown only saying: this error can only occur at run time if the definit

7条回答
  •  清歌不尽
    2020-11-29 04:21

    When the compiler compiled the code that is throwing the error, there was some other class with a field, and your class could access this field (either reading or changing the value).

    On runtime, the other class somehow has no field with this name, which results in the mentioned error.

    One reason might be that the second class changed without the first one being recompiled. Recompile all your classes, and you should either get a compiler error (which will give you more information on how to solve this), or the class will reference the right class.

    Another reason could be that you have some class in more than one jar file (or directory) in the class path (in different versions), resulting in some other class using the wrong one. Check all your jars on duplicate classes.

提交回复
热议问题