aSmack 错误:XMPPConnection 是抽象的;无法实例化

Posted

技术标签:

【中文标题】aSmack 错误:XMPPConnection 是抽象的;无法实例化【英文标题】:aSmack error: XMPPConnection is abstract; cannot be instantiated 【发布时间】:2014-05-07 00:20:25 【问题描述】:

我正在按照教程使用 android Studio 制作一个非常基本的聊天应用程序,但我收到了错误:

Error:(131, 45) 错误:XMPPConnection 是抽象的;不可能是 实例化

在以下行:

ConnectionConfiguration connConfig = new ConnectionConfiguration(HOST, PORT, SERVICE);
         XMPPConnection connection = new XMPPConnection(connConfig); 

我在尝试使用 XMPPConnection 元素时也遇到了一些“未处理的异常”。

还有教程链接:LINK

【问题讨论】:

我也遇到过这个错误。我下载了 Smack 4.0.0 库,我看到 XMPPConnection 是抽象的! 【参考方案1】:

看起来这在 Smack 4.0.0 中有所改变。文档仍未更新。

看起来他们会在 Smack 4.1 中再次改变它:

What was     
Connection connection = new XMPPConnection()
is
XMPPConnection connection = new XMPPTCPConnection()
in Smack 4 and will become
AbstractXMPPConnection connection = new XMPPTCPConnection()
in Smack 4.1

请看这个链接:https://igniterealtime.org/issues/browse/SMACK-574

还有 SMACK 4.0 的升级指南:https://community.igniterealtime.org/docs/DOC-2703

更新:

此外,看起来新的 Smack 4.x 库只能在 Java 7 及更高版本上运行。 Java 6 向后兼容性被破坏。

【讨论】:

【参考方案2】:

ConnectionConfiguration 也已更改。

XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
                    .setServiceName("example.org").setUsernameAndPassword("user", "password")
                    .setCompressionEnabled(false).build();

【讨论】:

以上是关于aSmack 错误:XMPPConnection 是抽象的;无法实例化的主要内容,如果未能解决你的问题,请参考以下文章

android实现xmppconnection服务

无法在 Android 设备上使用 asmack 15 登录 Google Talk

aSmack Android 文档和调试

Android asmack openfire接收文件

Asmack/Openfire 401 错误

在android中使用asmack获取错误的请求400错误