Android smack 4.1 连接问题
Posted
技术标签:
【中文标题】Android smack 4.1 连接问题【英文标题】:Android smack 4.1 issue with connection 【发布时间】:2015-04-19 09:20:06 【问题描述】:我正在尝试使用Smack
在android 中与GoogleTalk
建立连接。
我已经在互联网上关注了许多教程示例,但我似乎仍然无法使其工作。
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";
我上面的凭据是正确的...
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);
我收到java.lang.ExceptionInInitializeError
在这条线上
XMPPTCPConnectionConfiguration.Builder connConfig = XMPPTCPConnectionConfiguration.builder();
//第 184 行
这是完整的堆栈跟踪:
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.java:213)
at org.jivesoftware.smack.SmackInitialization.parseClassesToLoad(SmackInitialization.java:193)
at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:163)
at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:148)
at org.jivesoftware.smack.SmackInitialization.<clinit>(SmackInitialization.java:116)
Caused by: java.lang.NoClassDefFoundError: javax.naming.directory.InitialDirContext
at org.jivesoftware.smack.util.dns.javax.JavaxResolver.<clinit>(JavaxResolver.java:50)
有人可以帮我解决这个问题吗?我已经在 KitKat
和 JellyBean
上测试过这个
两者都有相同的例外,因此这不是操作系统版本上下文的故障。我错过了什么?
【问题讨论】:
你解决了这个问题吗?我自己也遇到了同样的错误 将用户名从 myemail@gmail.com 更改为 myemail。 @anshad 还是不行 【参考方案1】:我在使用 SMACK 4.1 建立连接时确实遇到了问题。 当我包含下面提到的所有这些库时,我成功建立了连接。试一试 :) 希望你成功。
-
jxmpp-core-0.4.1
jxmpp-util-cache-0.4.1
minidns-0.1.1
smack-android-4.1.0.jar
smack-android-extensions-4.1.0
smack-core-4.1.0
smack-extensions-4.1.0
smack-im-4.1.0
smack-tcp-4.1.0
【讨论】:
你能发布你的连接源代码吗?你在android中实现了上述目标吗?? @Sharp edge.... 是的,我能够与服务器建立连接并成功登录... :) 这是我发布我的源代码的问题的链接代码,你可以得到它:) ***.com/questions/29755230/…以上是关于Android smack 4.1 连接问题的主要内容,如果未能解决你的问题,请参考以下文章