java.lang.NoSuchMethodError
一般3種情況下會發生該例外
- 一個應用程式呼叫了一個類(類或者類的實體)中的方法,但是該類中已經不存在該方法的定義,這種情況在編譯時就能夠發現,
- jar 包沖突,導致類版本不一致
- A 類 呼叫 B類的方法,B類中也有該方法,但是B中的方法的回傳值調整了(如 int 改為 Integer),B類所在的jar包deploy了,但是A類所在的jar未deploy,導致該錯誤
先看下類圖

先看下原始碼
package java.lang;
/**
* Thrown if an application tries to call a specified method of a
* class (either static or instance), and that class no longer has a
* definition of that method.
* <p>
* Normally, this error is caught by the compiler; this error can
* only occur at run time if the definition of a class has
* incompatibly changed.
*
* @author unascribed
* @since JDK1.0
*/
public
class NoSuchMethodError extends IncompatibleClassChangeError {
private static final long serialVersionUID = -3765521442372831335L;
/**
* Constructs a <code>NoSuchMethodError</code> with no detail message.
*/
public NoSuchMethodError() {
super();
}
/**
* Constructs a <code>NoSuchMethodError</code> with the
* specified detail message.
*
* @param s the detail message.
*/
public NoSuchMethodError(String s) {
super(s);
}
}
對原始碼的注釋做個簡單的翻譯:
如果一個應用程式呼叫了一個類(類或者類的實體)中的方法,但是該類中已經不存在該方法的定義,則會拋出該例外,
通常情況下,這個錯誤會在編譯期被發現,當且僅當類的定義發生了不兼容的改變時,會發生在運行期,
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/514146.html
標籤:其他
上一篇:10分鐘教你寫一個資料庫
