Unable to get PayloadItem in HandlePublishedItems

Hello, I am having issues with handlePublishedItems. I am trying to extract the payload sent from my PubSub, but I keep getting the following error:

5673-5703/app.test.com.myxmpp E/AbstractXMPPConnection﹕ Exception in packet listener java.lang.ClassCastException: org.jivesoftware.smackx.pubsub.Item cannot be cast to org.jivesoftware.smackx.pubsub.PayloadItem

This is my following code for handlePublishedItems:

Here is the payload I am sending:

leafNode.send(new PayloadItem("test " + System.currentTimeMillis(), new SimplePayload(“book”, “pubsub:test:book”, “Two Towers”)));

I am following the example directly from here:

https://www.igniterealtime.org/builds/smack/docs/latest/documentation/extensions /pubsub.html

Any help is appreciated.

Thank you!

I discovered the problem. The guide had you set setDeliverPayloads to false, but that’s only the case if the item doesn’t have a payload. If it does have a payload, you need to set it true. Finally got that working (all I had to do was read the "LeafNode docs carefully).