Why am I getting null as the status?

Through the following code, a user named tester adds another user named sanika to his friend list.The SubscriptionMode is set to accept_all.

The function connectTester connects tester to the server and then after adding sanika, tester tries to find the status of sanika which was set as Having Lunch but instead null gets printed. Why is it so ?

`public static void main(String[] args) {
try {
Connection connection = new XMPPConnection(“localhost”);
connection.connect();
connection.login(“sanika”, “tester”);
Roster r = connection.getRoster();
r.setSubscriptionMode(Roster.SubscriptionMode.accept_all);
Presence p = r.getPresence("sanika@sanika.com");
p.setType(Presence.Type.available);
p.setStatus(“Having Lunch :)”);
connection.sendPacket§;
Thread.sleep(3000); // SLEEP FOR 3 SECONDS

         connectTester(); 

         Thread.sleep(30000); // SLEEP FOR 30 SECONDS

     }   catch(Exception exc) {
         exc.printStackTrace();
         }  
}

public static void connectTester() {
    try {
        Connection connection = new XMPPConnection("localhost");
        connection.connect();
        connection.login("tester", "tester");
        Roster r = connection.getRoster();
        String group[] = {"Friend List"};
        r.createGroup("Friend List");
        r.createEntry("sanika@sanika.com", "sanika", group);
        Presence p = r.getPresence("sanika@sanika.com");

        System.out.println(p.getStatus());
                        // THE ABOVE STATEMENT PRINTS NULL

    }catch(Exception exc) {
        exc.printStackTrace();
    }
}`

The statement System.out.println(p.getStatus()) inside the function connectTester prints null.

My guess is you’re doing something wrong, however I’m not sure exactly what (I personally have not played around with smack too much).

http://fisheye.igniterealtime.org/browse/~br=trunk/smack/trunk/source/org/jiveso ftware/smack/packet/Presence.java?r=13428

If you look at the source for Presence.class, there are multiple constructors. Perhaps you are using the wrong constructor or missing some process that needs to be done first? the String status is initially set to null in the class file, so something has to change it before it will return anything else (there’s a setStatus() method as well as the constructor that sets it… )