Problema ao Ler arquivo XML

0 respostas
J

Bom dia a todos, estou com um probleminha ao ler um arquivo XML.
Quando chega a hora de ler o arquivo ele me retorna null (java.lang.NullPointerException)

Estou usando o Netbeans 5.5, framework kxml para j2me

public void parse(final String url) {
        Thread t = new Thread() {
            public void run() {
                // set up the network connection
                try {
                    c = (StreamConnection)Connector.open(url);
                    s = c.openInputStream();
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    try {
                        if (c != null) c.close();
                    } catch (IOException ignored) {}
                }
            }
        };
        t.start();
    }
    public void Ler() {
        Attribute att = null;      
        this.parse("http://localhost/login.xml");
        //this.parse("E:\\http\\login.xml");
        try {            
            XmlParser parser = new XmlParser(new InputStreamReader(s));
            Document document = new Document();
            document.parse(parser);
            
            Element root = document.getRootElement();
            int children = root.getChildCount();
            
            for (int i=0; i < children; i++) {
                if (root.getType(i) == Xml.ELEMENT) {
                    Element el = root.getElement(i);
                    
                    int babies = el.getChildCount();
                    for (int j=0; j < babies; j++) {
                        if (el.getType(j) == Xml.ELEMENT) {
                            Element elName = (Element)el.getChild(j);
                            if (elName.getName().equals("usuario")) {
                                att = elName.getAttribute("value");
                                Usuario = att.getValue();
                            } else if (elName.getName().equals("senha")) {
                                att = elName.getAttribute("value");
                                Senha = att.getValue();
                            }
                        }
                    }
                }
            }
        } catch (IOException err) {
            System.out.println(err);
            err.printStackTrace();
        }
    }

Este é o arquivo XML

<?xml version="1.0" encoding="iso-8859-1"?>
<login>
   <usuario value="MASTER"/>
   <senha value="xkiller"/>
</login>
Criado 4 de janeiro de 2007
Respostas 0
Participantes 1