I have problems when compiling a program
When doing clean and build in netbeans, I get the following error:
error: not suitable constructor found for User (String, String, Boolean) adminList.add (new User (mail, pass, isAdmin)); Constructor User.User () is not applicable (current and formal argument lists differ in length) Constructor User.User (String, String, String, String) is not applicable (current and formal argument lists differ in length)
but the class User
has a constructor that if adapted to the needs, with a code it looks like this:
public class User {
private String mail;
private String pass;
private boolean admin;
public User() {}
public User(String mail, String pass, boolean admin) {
this.mail = mail;
this.pass = pass;
this.admin = admin;
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
public boolean isAdmin() {
return admin;
}
public void setAdmin(boolean admin) {
this.admin = admin;
}
@Override
public String toString() {
return "User{" + "mail=" + mail + ", pass=" + pass + ", admin=" + admin + '}';
}
} and the class where I generate a problem is one where I'm extracting information from an xml file, the method is the following:
public ArrayList<User> getAllAdmin() {
try {
ArrayList<User> adminList = new ArrayList<>();
NodeList nodeList = (NodeList) xPath.compile(EXPRESSION).evaluate(xmlDocument, XPathConstants.NODESET);
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
String mail = element.getElementsByTagName("mail")
.item(0).getChildNodes().item(0).getNodeValue();
String pass = element.getElementsByTagName("pass")
.item(0).getChildNodes().item(0).getNodeValue();
String adminString = element.getElementsByTagName("isAdmin")
.item(0).getChildNodes().item(0).getNodeValue();
boolean isAdmin = false;
if (adminString.equalsIgnoreCase("true")) {
isAdmin = true;
}
adminList.add(new User(mail, pass, isAdmin));
}
}
return adminList;
} catch (XPathExpressionException ex) {
System.err.println("getAllDataFromXML (Admin side) method, XPathExpressionException: " + ex.getMessage() + "\n" + Arrays.toString(ex.getStackTrace()));
}
return null;
}
It also generates this error for me, where it tells me that it does not find the necessary method.
error: can not find symbol if (validationArray.get (i) .getMail (). equalsIgnoreCase (user.getMail ())) { symbol: method getMail () location: variable user of type User
but the method does exist, and the error occurs in this method:
public boolean writeNewUser(User user) {
boolean aux = false;
ArrayList<User> validationArray = getAllAdmin();
boolean exist = false;
for (int i = 0; i < validationArray.size(); i++) {
if (validationArray.get(i).getMail().equalsIgnoreCase(user.getMail())) {
exist = true;
}
}
if (!exist) {
try {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(new File("web/WEB-INF/file/" + xmlFile));
doc.getDocumentElement().normalize();
/*Nodo padre: <user>*/
Node rootNode = doc.getDocumentElement();
/*Nueva etiqueta para el documento*/
Element newAdmin = doc.createElement("admin");
/*etiquetas hijas de admin*/
Element newMail = doc.createElement("mail");
newMail.setTextContent(user.getMail());
Element newPass = doc.createElement("pass");
newPass.setTextContent(user.getPass());
Element newIsAdmin = doc.createElement("isAdmin");
newIsAdmin.setTextContent(String.valueOf(user.isAdmin()));
/*relacionar los nuevos elementos hijos a la etiqueta padre*/
newAdmin.appendChild(newMail);
newAdmin.appendChild(newPass);
newAdmin.appendChild(newIsAdmin);
/*relacionar los elementos con la etiqueta raiz*/
rootNode.appendChild(newAdmin);
/*generar archivo xml*/
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File("web/WEB-INF/file/" + xmlFile));
transformer.transform(source, result);
aux = true;
} catch (SAXException ex) {
Logger.getLogger(AdminManager.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(AdminManager.class.getName()).log(Level.SEVERE, null, ex);
} catch (TransformerConfigurationException ex) {
Logger.getLogger(AdminManager.class.getName()).log(Level.SEVERE, null, ex);
} catch (TransformerException ex) {
Logger.getLogger(AdminManager.class.getName()).log(Level.SEVERE, null, ex);
} catch (ParserConfigurationException ex) {
Logger.getLogger(AdminManager.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
System.out.println("user already exist");
}
return aux;
}
I tried to re-do the classes and I still generate the same problem, I do not know what is wrong with the code. Thanks