NullPointerException with Simple HTMLserializer

288 Views Asked by At


I am trying to parse html from a TagNode. The problem is, there is an inner exception prevents it from working. Here is my call:

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

root of course is not null, and obviously serializer is not null also.

This is the stack trace:

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)

UPDATE: I found a workaround, without even using HtmlSerializer or TagNode (using html I already extracted successfully and some string commands)

2

There are 2 best solutions below

1
On

According to sources from HtmlCleaner, HtmlSerializer.isMinimizedTagSyntax() calls CleanerProperties.getTagInfoProvider(). And in CleanerProperties.java

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

There's no method to set it in CleanerProperties. tagInfoProvider must be set somehow, before you use it.

I think, to find out how, you must dig a bit into HtmlCleaner's documentation, which is available at Java code usage for example.

0
On

I have just the same problem and spent quite a lot of time finding solution.

CleanerProperties props = new CleanerProperties() {

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

};

HtmlSerializer simpleHtmlSerializer = new SimpleHtmlSerializer(props);
String message = simpleHtmlSerializer.getAsString(tagNode, true);