[英]failing to instantiate an object through a constructor in java
i'm trying to instantiate an object through a constructor from another class in a different package , and i get an error saying我正在尝试通过不同包中另一个类的构造函数实例化一个对象,我收到一条错误消息
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem: The constructor Utilisateur(String, String, String, String, String, String, float, String, String, String) is undefined线程“AWT-EventQueue-0”中的异常 java.lang.Error: 未解决的编译问题:构造函数 Utilisateur(String, String, String, String, String, String, float, String, String, String) 未定义
i think it has to do with the way i declared my setters but i'm not sure, hopefully you'll know我认为这与我声明我的二传手的方式有关,但我不确定,希望你会知道
these are the variables, setters(not all of them), and constructor in common.Utilisateur.java这些是 common.Utilisateur.java 中的变量、setter(不是全部)和构造函数
private static String login;
private static String password;
public static void setLogin(String login) {
Utilisateur.login = login;
}
public static void setPassword(String password) {
Utilisateur.password = password;
}
public Utilisateur(String login,
String password,
String nom,
String prenom,
String sexe,
String date,
float poids,
String adresse,
String telephone,
String email) {
setLogin(login);
setPassword(password);
setNom(nom);
setPrenom(prenom);
setSexe(sexe);
setDate(date);
setPoids(poids);
setAdresse(adresse);
setTelephone(telephone);
setEmail(email);
}
constructor call in views.connexion.java views.connexion.java 中的构造函数调用
Utilisateur user = new Utilisateur(login.getText(),
password.getText(),
nom.getText(),
prenom.getText(),
sexe.getSelection().getActionCommand(),
date,
Float.parseFloat(poids.getText()),
adresse.getText(),
telephone.getText(), email.getText());
I would assume, that the package is working with outdated classes and either the package containing Utilisateur
should be re-compiled or the depending package be updated.我假设该包正在使用过时的类,并且应该重新编译包含Utilisateur
的包或更新依赖包。 On a side note, it's highly advisable to reduce the number of parameters by ie using the Builder
pattern in order to make it more manageable.附带说明一下,强烈建议使用Builder
模式来减少参数的数量,以使其更易于管理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.