Quantcast
Channel: Ignite Realtime : Unanswered Discussions - Support
Viewing all articles
Browse latest Browse all 4979

Using smack 4.1 on android, giving exception in connection

$
0
0

I'm trying to make a connection with GoogleTalk in android using Smack 4.1.

I've followed numerous tutorials examples on the internet yet still I can't seem to make it work.

 

   public static final String HOST = "talk.google.com";

 

    public static final int PORT = 5222;

    public static final String SERVICE = "gmail.com";

    public static final String USERNAME = "myemail@gmail.com";

    public static final String PASSWORD = "mypassword";

 

My above credentials are correct...

 

     XMPPTCPConnectionConfiguration.Builder connConfig = XMPPTCPConnectionConfiguration.builder();

       connConfig.setSecurityMode(ConnectionConfiguration.SecurityMode.required);

       connConfig.setUsernameAndPassword(USERNAME, PASSWORD);

       connConfig.setServiceName(SERVICE);

       connConfig.setHost(HOST);

       connConfig.setPort(PORT);

       connConfig.setDebuggerEnabled(true);

       //setCompressionEnabled(false).build();

       //(HOST, PORT, SERVICE);

       XMPPTCPConnection connection = new  XMPPTCPConnection(connConfig.build());

         try {

           connection.connect();

           Log.i("XMPPChatDemoActivity",  "[SettingsDialog] Connected to "+connection.getHost());

         } catch (XMPPException ex) {

             Log.e("XMPPChatDemoActivity",  "[SettingsDialog] Failed to connect to "+ connection.getHost());

             Log.e("XMPPChatDemoActivity", ex.toString());

             setConnection(null);

         }

         catch(SmackException ex){

             Log.e("XMPPChatDemoActivity",  "[SettingsDialog] Failed to connect to "+ connection.getHost());

             Log.e("XMPPChatDemoActivity", ex.toString());

             setConnection(null);

         }

         catch(IOException ex){

             Log.e("XMPPChatDemoActivity",  "[SettingsDialog] Failed to connect to "+ connection.getHost());

             Log.e("XMPPChatDemoActivity", ex.toString());

             setConnection(null);

         }

 

I get `java.lang.ExceptionInInitializeError`

 

on this line

 

    XMPPTCPConnectionConfiguration.Builder connConfig = XMPPTCPConnectionConfiguration.builder();  //line 184

 

Here is the complete stack trace:

 

     FATAL EXCEPTION: Thread-120

    java.lang.ExceptionInInitializerError

    at com.example.samsungchatexample.MainActivity$4.run(MainActivity.java:184)

     at java.lang.Thread.run(Thread.java:856)

    Caused by: java.lang.ExceptionInInitializerError

    at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96 )

    at org.jivesoftware.smack.ConnectionConfiguration.<clinit>(ConnectionConfiguration .java:38)

 

    Caused by: java.lang.ExceptionInInitializerError

    at java.lang.Class.classForName(Native Method)

    at java.lang.Class.forName(Class.java:217)

    at org.jivesoftware.smack.SmackInitialization.loadSmackClass(SmackInitialization.j ava:213)

    at org.jivesoftware.smack.SmackInitialization.parseClassesToLoad(SmackInitializati on.java:193)

    at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitializatio n.java:163)

    at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitializatio n.java:148)

    at org.jivesoftware.smack.SmackInitialization.<clinit>(SmackInitialization.java:11 6)

 

    Caused by: java.lang.NoClassDefFoundError: javax.naming.directory.InitialDirContext

    at org.jivesoftware.smack.util.dns.javax.JavaxResolver.<clinit>(JavaxResolver.java :50)

 

 

Can someone please help me with this ? I've tested this on `KitKat` and `JellyBean`

Same exception on both so this is not a glitch with context to OS versions. What am I missing ?

 

note: I've tested it on emulator as well as on real device.

 

**EDIT**

 

I've added all the jars which were included in Smack 4.1


Viewing all articles
Browse latest Browse all 4979

Trending Articles