本文主要是介绍java.lang.NoSuchMethodException init(),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
今天使用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();}
这篇关于java.lang.NoSuchMethodException init()的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!