java.lang.NoSuchMethodException ()

來源:互聯網
上載者:User

今天使用Mybatis串連資料庫時報出了java.lang.NoSuchMethodException 的錯誤,錯誤資訊如下,


錯誤提示,出錯地點是Player的BEAN類執行個體化出了錯,Player代碼如下

public class Player {private int pid;private String pname;private String position;private int cid;private Club club;//多對一關聯性public int getPid() {return pid;}public void setPid(int pid) {this.pid = pid;}public String getPname() {return pname;}public void setPname(String pname) {this.pname = pname;}public String getPosition() {return position;}public void setPosition(String position) {this.position = position;}public int getCid() {return cid;}public void setCid(int cid) {this.cid = cid;}public Club getClub() {return club;}public void setClub(Club club) {this.club = club;}public Player(int pid, String pname, String position, int cid, Club club) {super();this.pid = pid;this.pname = pname;this.position = position;this.cid = cid;this.club = club;}@Overridepublic String toString() {return "Player [pid=" + pid + ", pname=" + pname + ", position=" + position + ", cid=" + cid + "]";}}
最後發現是我在代碼最後寫了個有參構造,重載了建構函式,而Mybatis在load進一個bean類時,需要無參構造從而導致了該錯誤,

解決方案,給代碼加上午參構造即可。

public Player() {super();}







聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.