|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Member
Iscritto dal: Dec 2007
Messaggi: 40
|
[java] remove child
ciao a tutti
ho un problema la removeChild mi da un errore di null pointer exception ma non capisco perchè public class elimina{ private static final long serialVersionUID = 1L; static String codProd,codArt; static Document doc = null; static PrintWriter out = null; static Node appProd,appArt=null; private static void elimina(String CodArt) { try { Element element = (Element)doc.getElementById("45"); element.getParentNode().removeChild(element); doc.normalize(); } catch(Exception e){System.out.println(" " + e);} } public static void main(String arg[]) { Document doc = null; PrintWriter out = null; Node appProd,appArt=null; codProd = "codProd"; codArt = "45"; try{ DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance(); DocumentBuilder db=dbf.newDocumentBuilder(); doc=db.parse("Prodotti.xml"); elimina(codArt); } catch(Exception e){ } }} nel file xml codArt è un attributo di tipo id quindi la funzione mi dovrebbe tornare un nodo.....ma non riesco a eliminarlo spero in un vostro aiuto |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 16:27.