【问题标题】:Codenameone HTMLParser gives NPECodenameone HTMLParser 提供 NPE
【发布时间】:2014-06-22 01:21:13
【问题描述】:

在尝试使用 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)

我在这里做错了吗?

【问题讨论】:

    标签: codenameone


    【解决方案1】:

    您需要使用XMLParserHTMLParser 设计用于HTMLComponent

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-03
      • 1970-01-01
      • 2017-07-18
      • 1970-01-01
      • 2013-11-25
      • 2014-10-16
      • 2016-01-06
      • 1970-01-01
      相关资源
      最近更新 更多