Skip to main content

how can i remove child into file xml using J2ME

No replies
voilemiss
Offline
Joined: 2009-05-19
Points: 0

try {
HttpConnection httpConnection = (HttpConnection) Connector.open("http://127.0.0.1:8080/MioSite/users.xml");

KXmlParser parser = new KXmlParser();
InputStreamReader reader = new InputStreamReader( httpConnection.openInputStream());
parser.setInput( reader );

Document dom = new Document();
dom.parse( parser );
Element root=dom.getRootElement();

OutputStream os = httpConnection.openOutputStream();

org.kxml2.io.KXmlSerializer s = new org.kxml2.io.KXmlSerializer();

root.removeChild(1);

dom.write(s);

s.flush ();

os.close();
httpConnection.close();

} catch (Throwable t) {
System.out.println("Exception:"+t);
t.printStackTrace();
}
}

but when i run i find a trouble

Exception:java.lang.NullPointerException
java.lang.NullPointerException
at org.kxml2.io.KXmlSerializer.startDocument(+6)
at org.kxml2.kdom.Document.write(+14)
at Midlet.startApp(Midlet.java:41)
at javax.microedition.midlet.MIDletProxy.startApp(MID letProxy.java:43)
at com.sun.midp.midlet.Scheduler.schedule(Scheduler.j ava:374)
at com.sun.midp.main.Main.runLocalClass(Main.java:466 )
at com.sun.midp.main.Main.main(Main.java:120)
Edit/Delete Message