I need to use XML in a university job and I had problems with a Get method I had to implement in a Collection p>
After a while I took a look at some websites to do this and found the following tutorial , it has a Contact class as follows below with the phones field, and a statement is given to create a Get for her, I created it and the structure was summarized like this:
public class Contato {
private Collection telefones = new ArrayList();
public Collection getTelefones() {
return telefones;
}
}
But in the code snippet below I got an error:
--- Change phone type to Object ---
for (Telefone fone : contato.getTelefones()) {
tagFone = doc.createElement("Telefone");
idFone = doc.createElement("id");
dddFone = doc.createElement("ddd");
numeroFone = doc.createElement("numero");
//Insere os valores de telefones nas tags referentes
idFone.setTextContent(String.valueOf(fone.getId()));
dddFone.setTextContent(String.valueOf(fone.getDdd()));
numeroFone.setTextContent(String.valueOf(fone.getNumero()));
//Insere as tags Telefone na tag Telefone
tagFone.appendChild(idFone);
tagFone.appendChild(dddFone);
tagFone.appendChild(numeroFone);
//Insere a tag Telefone na tag pai Telefones
tagFones.appendChild(tagFone);
}
I tried something different but could not solve it. I believe that it is in the Get method that I implemented myself, and if the community can help me, I will be grateful.