Quantcast
Channel: Ignite Realtime : Discussion List - All Communities
Viewing all articles
Browse latest Browse all 10742

XMPPStringUtils error for smack

$
0
0

Hi All,

 

I wrote a simple client java code to send a message to the server. However, I ran into some issues when running the code. I have an idea that my issue has alot to do with the libraries that have included. Below, I have included my java code. Secondly, the error that I received when I run the java code. Lastly, the libraries that I use to run the code. I am using eclipse, android Developer Tools Build: v22.6.2-1085508. Please give me suggestions on how to fix the issue ...

 

Code:

-------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --------------------------------------------------------

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

 

import org.jivesoftware.smack.AbstractXMPPConnection;

import org.jivesoftware.smack.Chat;

import org.jivesoftware.smack.ChatManager;

import org.jivesoftware.smack.ChatManagerListener;

import org.jivesoftware.smack.ConnectionConfiguration;

import org.jivesoftware.smack.MessageListener;

import org.jivesoftware.smack.Roster;

import org.jivesoftware.smack.Roster.SubscriptionMode;

import org.jivesoftware.smack.SmackException.NotConnectedException;

import org.jivesoftware.smack.XMPPException;

import org.jivesoftware.smack.packet.Message;

import org.jivesoftware.smack.tcp.XMPPTCPConnection;

 

 

 

public class SuperSimpleXMPPClient {

 

    private static String userName =" "; // deleted this for obvious reasons

    private static String password = " "; // deleted this for obvious reasons

 

    public static void main(String[] args) {

        try {

 

            ConnectionConfiguration config = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");

            AbstractXMPPConnection connection = new XMPPTCPConnection(config);

            connection.connect();

            connection.login(userName, password);

 

            Roster roster = connection.getRoster();

            roster.setSubscriptionMode(SubscriptionMode.accept_all);

 

 

            ChatManager chatmanager = ChatManager.getInstanceFor(connection);

            chatmanager.addChatListener(new ChatManagerListener() {

                        public void chatCreated(final Chat chat, final boolean createdLocally) {

                            chat.addMessageListener(new MessageListener() {

                                public void processMessage(Chat chat, Message message) {

                                    String text = message.getBody();

 

                                    System.out.println("Received message from " + chat.getParticipant() + ": " + text);

                                    if(text != null) {

                                        respondInReverse(chat, text);

                                    }

                                }

                            });

                        }

                    });

 

            waitForExit();

 

            connection.disconnect();

 

        } catch (Throwable t) {

            t.printStackTrace();

        }

    }

 

    private static void respondInReverse(Chat chat, String text) {

        char[] chars = text.toCharArray();

        for(int i = 0; i < chars.length / 2; ++i) {

            char temp = chars[i];

            chars[i] = chars[chars.length - i - 1];

            chars[chars.length - i - 1] = temp;

        }

 

        String response = new String(chars);

        try {

            chat.sendMessage(response);

        } catch (XMPPException | NotConnectedException e) {

            System.out.println("Unexception while responding!");

            e.printStackTrace();

        }

    }

 

    private static void waitForExit() throws IOException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        while (!reader.readLine().equals("exit")) {

 

        }

    }

 

}

 

Error:

-------------------------------------------------------------------------------- -------------------------------------------------------------------------------- ------------------------------------------------------

 

xception in thread "Smack Packet Reader (0)" java.lang.NoClassDefFoundError: org/jxmpp/util/XmppStringUtils

    at org.jivesoftware.smack.ConnectionConfiguration.setServiceName(ConnectionConfigu ration.java:208)

    at org.jivesoftware.smack.AbstractXMPPConnection.setServiceName(AbstractXMPPConnec tion.java:473)

    at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$700(XMPPTCPConnection.java: 96)

    at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPC onnection.java:1008)

    at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$200(XMPPTCPCon nection.java:876)

    at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnecti on.java:908)

Caused by: java.lang.ClassNotFoundException: org.jxmpp.util.XmppStringUtils

    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)

    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)

    at java.security.AccessController.doPrivileged(Native Method)

    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)

    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)

    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)

    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

    ... 6 more

org.jivesoftware.smack.SmackException$NoResponseException

    at org.jivesoftware.smack.AbstractXMPPConnection.throwConnectionExceptionOrNoRespo nse(AbstractXMPPConnection.java:460)

    at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$300(XMPPTCPConnection.java: 96)

    at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.startup(XMPPTCPConnec tion.java:939)

    at org.jivesoftware.smack.tcp.XMPPTCPConnection.initConnection(XMPPTCPConnection.j ava:501)

    at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(XMPPTCPC onnection.java:459)

    at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection. java:820)

    at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.ja va:302)

    at SuperSimpleXMPPClient.main(SuperSimpleXMPPClient.java:30)

 

-------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --------------------------------------------------

Here are the list of libraries include in the java build path:

 

smack-core-4.1.0-alpha1-SNAPSHOT.jar

smack-tcp-4.1.0-alpha1-SNAPSHOT.jar

xpp3-1.1.4c.jar

 

Cheers,

KA


Viewing all articles
Browse latest Browse all 10742

Trending Articles