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
.