AnsweredAssumed Answered

Smack problem

Question asked by petr.bel on Aug 20, 2010
Latest reply on Aug 28, 2010 by petr.bel

Hi everyone,

not sure if I´m at right place here, but despite that, I hope you can help me .

 

I try to make a little app that just connects jabber and sends a message. I downloaded Smack and linked it.

My code:

 

import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.packet.Message;


class Jabber{

public static void main(final String[] args) {

 

    ConnectionConfiguration config = new ConnectionConfiguration("jabbim.cz", 5222); //got acc 3.14.TR@jabbim.cz - czech jabber server
config.setCompressionEnabled(true);
config.setSASLAuthenticationEnabled(true);

XMPPConnection connection = new XMPPConnection(config);

try{
System.out.println("before connection");
connection.connect();
      connection.login("3.14.TR", "pass", "3.14.TR@jabbim.cz/Smack");
System.out.println("connected");
}
catch(Exception a){
System.out.println("connection error");
return;
}

 

ChatManager chatmanager = connection.getChatManager();
    Chat newChat = chatmanager.createChat("myFriend@jabbim.cz", new MessageListener() {
public void processMessage(Chat chat, Message message) {
System.out.println("Received message: " + message);
}
});

 

try {
newChat.sendMessage("hoooooooooooj!");
}
catch (XMPPException e) {
System.out.println("Error Delivering block");
}
connection.disconnect();

 


  }

}

 

Compilation is always successful, but trying running program throws few exceptions:

 

before connection //means connection created, but not connected
java.lang.NullPointerException
at org.jivesoftware.smack.util.Base64.encodeBytes(Base64.java:636)
at org.jivesoftware.smack.sasl.SASLMechanism.challengeReceived(SASLMechanism.java: 152)
at org.jivesoftware.smack.SASLAuthentication.challengeReceived(SASLAuthentication. java:492)
at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:338)
at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:44)
at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:76)
connection error

 

can anyone help me please?

thanks a lot

petr bel

 

 

public static void main(final String[] args) {

 

ConnectionConfiguration config = new ConnectionConfiguration("jabbim.cz", 5222);
config.setCompressionEnabled(true);
config.setSASLAuthenticationEnabled(true);

XMPPConnection connection = new XMPPConnection(config);

try{
System.out.println("before connection");
connection.connect();
connection.login("3.14.TR", "cat8x8r1", "3.14.TR@jabbim.cz/Smack");
System.out.println("connected");
}
catch(Exception a){
System.out.println("connection error");
return;
}

 

ChatManager chatmanager = connection.getChatManager();
Chat newChat = chatmanager.createChat("joyce@jabbim.cz", new MessageListener() {
public void processMessage(Chat chat, Message message) {
System.out.println("Received message: " + message);
}
});

 

try {
newChat.sendMessage("hoooooooooooj!");
}
catch (XMPPException e) {
System.out.println("Error Delivering block");
}
connection.disconnect();

 


}

Outcomes