简体   繁体   English

无法通过java中的构造函数实例化对象

[英]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.

相关问题 无法使用Java中的参数化构造函数实例化对象 - Unable to instantiate an object using parameterized Constructor in java Spring使用Java-Config(而非XML)使用构造函数争论实例化对象 - Spring instantiate object with constructor arguements using java-config (not XML) 您可以使用无类型对象实例化Java类构造函数吗? - Can you instantiate a Java class constructor with an untyped object? 如何在方法Java之外使用其构造函数实例化对象 - How to instantiate an object using it's constructor outside a method java 我如何通过将对象作为参数传递来实例化CDI bean,就像我从参数化构造函数中以普通Java实例化新对象一样? - How do I instantiate a CDI bean by passing an object as parameter just like I instantiate a new object in plain Java from a parameterized constructor? Java:实例化对象的方法 - Java : the method to instantiate an object 实例化对象Java - Instantiate Object Java 如何在java中实例化一个对象? - How to instantiate an object in java? 如何通过反射实例化未知被测类的构造函数中的参数数量的Java中的类? - How to instantiate class in Java where number of parameters in constructor of class under test is unknown through Reflection? Java在Java中实例化Short对象 - Java instantiate Short object in Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM