How to accept and reject a subscription manually?

Below is the function to process the packet:

public void processPacket(Packet p_packet)


if (p_packet instanceof Message)




else if (p_packet instanceof Presence)


Presence l_presence = (Presence)p_packet;

if (l_presence.getType() == Presence.Type.SUBSCRIBE)


System.out.println("Subscription from " + l_presence.getFrom());







Below is the way I add packet listener:

l_xmppConn.addPacketListener(this, new PacketTypeFilter(Message.class));

l_xmppConn.addPacketListener(this, new PacketTypeFilter(Presence.class));

I want to learn how to accept and reject the subscription in code. I got the error at g_xmppConn.sendPacket(l_presence); line:

Subscription from usera@localhost


at Test.processPacket(

at org.jivesoftware.smack.PacketReader$ListenerWrapper.notifyListener(PacketReader .java:817)

at org.jivesoftware.smack.PacketReader.processListeners(

at org.jivesoftware.smack.PacketReader.access$100(

at org.jivesoftware.smack.PacketReader$

Can expert show me how to do both ?

Thanks !

Most likely your g_xmppConn is null. Check if you’'ve init-ed it, and do a println before that line to see if its null.

Stupid me. I have global and local to XMPPConnection. I used local to get connection and global is null