Codenameone HTMLParser给出了NPE

时间:2014-06-21 11:23:43

标签: codenameone

我在尝试使用HTMLParser解析基本的html字符串时不断获得NPE。 代码:

    String html = "<html><body>Test</body></html>";
    HTMLParser parser = new HTMLParser();
    System.out.println(parser);
    ByteArrayInputStream ba = new ByteArrayInputStream(html.getBytes());
    System.out.println("ba::" + ba);
    InputStreamReader isr = new InputStreamReader(ba);
    System.out.println("isr1::" + isr);                
    HTMLElement root = parser.parseHTML(new InputStreamReader(new ByteArrayInputStream(html.getBytes())));        
    Hashtable data = root.getAttributes();
    Set kys = data.keySet();
    for (Object o : kys) {
        System.out.println("key::" + (String) o);
        System.out.println("value::" + (String) data.get(o));
    }

堆栈跟踪:

Caused by: java.lang.NullPointerException
at com.codename1.ui.html.HTMLParser.parseTagContent(HTMLParser.java:81)
at com.codename1.xml.XMLParser.parse(XMLParser.java:267)
at com.codename1.ui.html.HTMLParser.parseHTML(HTMLParser.java:174)
at userclasses.StateMachine.beforeMain(StateMachine.java:52)

我在这里做错了吗?

1 个答案:

答案 0 :(得分:0)

您需要使用XMLParserHTMLParser旨在用于HTMLComponent