How to create a custom IQ packet

I try to create a custom IQ packet to register push token on Android.

Here is my custom IQ class

class MyCustomIQ extends IQ {
        String token;     protected MyCustomIQ(String token) {
        super("query", "urn:xmpp:registernoti");
        this.token = token;
    }     @Override
    protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
        xml.element("token", token);
        xml.element("devicetpye", "android");         return xml;

And here how I create IQ

MyCustomIQ iq = new MyCustomIQ(pushToken);

After I created the IQ packet, I tried to use toString() to show the XML in logcat, but it turn to error below. An I am using Smack API version:4.1.3 (4.1.3 2015-07-15)

java.lang.NullPointerException: Attempt to invoke interface method 'int java.lang.CharSequence.length()' on a null object reference
        at org.jivesoftware.smack.util.LazyStringBuilder.length(
        at org.jivesoftware.smack.util.LazyStringBuilder.toString(
        at org.jivesoftware.smack.util.XmlStringBuilder.toString(
        at org.jivesoftware.smack.packet.Stanza.toString(
        at org.jivesoftware.smack.AbstractXMPPConnection.callConnectionAuthenticatedListener(
        at org.jivesoftware.smack.AbstractXMPPConnection.afterSuccessfulLogin(
        at org.jivesoftware.smack.tcp.XMPPTCPConnection.afterSuccessfulLogin(
        at org.jivesoftware.smack.tcp.XMPPTCPConnection.loginNonAnonymously(
        at org.jivesoftware.smack.AbstractXMPPConnection.login(
        at org.jivesoftware.smack.AbstractXMPPConnection.login(


Some object within XmlStringBuilder is null. Most likely ‘token’.

Hint: Run with assertions enabled to catch the misuse earlier. Also don’t use “urn:xmpp” as prefix for your namespace if it isn’t registered with the registrar. Use e.g. a URL (or URN) under your control.

Thanks a lot!

I will change the namespace too~