0


我正在尝试从TagNode. 问题是,有一个内部异常阻止它工作。这是我的电话:

CleanerProperties props = new CleanerProperties();
SimpleHtmlSerializer serializer = new SimpleHtmlSerializer(props);
changes.setHtmlForTimetable(serializer.getAsString(root));

root 当然不为空,显然序列化器也不为空。

这是堆栈跟踪:

01-21 23:42:50.860: W/System.err(25196): java.lang.NullPointerException
01-21 23:42:50.865: W/System.err(25196):    at org.htmlcleaner.HtmlSerializer.isMinimizedTagSyntax(HtmlSerializer.java:54)
01-21 23:42:50.875: W/System.err(25196):    at org.htmlcleaner.HtmlSerializer.serializeOpenTag(HtmlSerializer.java:189)
01-21 23:42:50.880: W/System.err(25196):    at org.htmlcleaner.SimpleHtmlSerializer.serialize(SimpleHtmlSerializer.java:52)
01-21 23:42:50.885: W/System.err(25196):    at org.htmlcleaner.Serializer.write(Serializer.java:249)
01-21 23:42:50.890: W/System.err(25196):    at org.htmlcleaner.Serializer.getAsString(Serializer.java:176)
01-21 23:42:50.900: W/System.err(25196):    at org.htmlcleaner.Serializer.getAsString(Serializer.java:197)
01-21 23:42:50.905: W/System.err(25196):    at org.htmlcleaner.Serializer.getAsString(Serializer.java:206)
01-21 23:42:50.915: W/System.err(25196):    at com.roneven.blich.GetChanges$1$1$1.callback(GetChanges.java:125)
01-21 23:42:50.920: W/System.err(25196):    at com.roneven.blich.GetChanges$1$1$1.callback(GetChanges.java:1)
01-21 23:42:50.930: W/System.err(25196):    at com.androidquery.callback.AbstractAjaxCallback.callback(AbstractAjaxCallback.java:501)
01-21 23:42:50.935: W/System.err(25196):    at com.androidquery.callback.AbstractAjaxCallback.afterWork(AbstractAjaxCallback.java:1269)
01-21 23:42:50.940: W/System.err(25196):    at com.androidquery.callback.AbstractAjaxCallback.run(AbstractAjaxCallback.java:993)
01-21 23:42:50.945: W/System.err(25196):    at android.os.Handler.handleCallback(Handler.java:725)
01-21 23:42:50.945: W/System.err(25196):    at android.os.Handler.dispatchMessage(Handler.java:92)
01-21 23:42:50.950: W/System.err(25196):    at android.os.Looper.loop(Looper.java:137)
01-21 23:42:50.950: W/System.err(25196):    at android.app.ActivityThread.main(ActivityThread.java:5191)
01-21 23:42:50.955: W/System.err(25196):    at java.lang.reflect.Method.invokeNative(Native Method)
01-21 23:42:50.955: W/System.err(25196):    at java.lang.reflect.Method.invoke(Method.java:511)
01-21 23:42:50.960: W/System.err(25196):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
01-21 23:42:50.960: W/System.err(25196):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
01-21 23:42:50.965: W/System.err(25196):    at dalvik.system.NativeStart.main(Native Method)

更新:我找到了一种解决方法,甚至没有使用 HtmlSerializer 或 TagNode (使用我已经成功提取的 html 和一些字符串命令)

4

2 回答 2

1

根据来自HtmlCleaner的消息,HtmlSerializer.isMinimizedTagSyntax()调用CleanerProperties.getTagInfoProvider(). 而在CleanerProperties.java

ITagInfoProvider tagInfoProvider = null;
...
public ITagInfoProvider getTagInfoProvider() {
    return tagInfoProvider;
}

没有办法设置它CleanerPropertiestagInfoProvider必须以某种方式设置,然后再使用它。

我认为,要找出方法,您必须深入研究 HtmlCleaner 的文档,例如Java 代码使用中提供的文档。

于 2013-01-21T22:09:59.943 回答
0

我也遇到了同样的问题,花了很多时间寻找解决方案。

CleanerProperties props = new CleanerProperties() {

    @Override
    public ITagInfoProvider getTagInfoProvider() {
        return DefaultTagProvider.getInstance();
    }

};

HtmlSerializer simpleHtmlSerializer = new SimpleHtmlSerializer(props);
String message = simpleHtmlSerializer.getAsString(tagNode, true);
于 2013-03-01T08:43:16.350 回答