【问题标题】:Stuck at the first step of making a chat client using smack卡在使用 smack 制作聊天客户端的第一步
【发布时间】:2017-07-19 11:38:36
【问题描述】:

我开始在 smack 和 eclipse 上使用 java 构建聊天客户端,所以我开始编写以下代码:

import org.jivesoftware.smack.XMPPConnection;

public class A {

// Create a connection to the igniterealtime.org XMPP server.
    XMPPConnection connection = new XMPPConnection("myserver.com");
    // Connect to the server
    connection.connect();
    // Most servers require you to login before performing other tasks.
    connection.login("admin2", "123");
public static void main(String[] args) {
    // TODO Auto-generated method stub
     A a= new A();

}

}

但我收到以下两个错误:

Syntax error on token "connect", Identifier expected after this token

Syntax error on token ".", @ expected after this token

有人可以帮我吗?

【问题讨论】:

    标签: java xmpp smack


    【解决方案1】:

    你不能把语句(比如 connection.connect() )放到方法体之外。

    试试这样的:

    public class A 
    {
        public void start()
        {
            XMPPConnection connection = new XMPPConnection("myserver.com");
            // Connect to the server
            connection.connect();
            // Most servers require you to login before performing other tasks.
            connection.login("admin2", "123");
        }
        public static void main(String[] args) 
        {
            // TODO Auto-generated method stub
            A a= new A();
            a.start();
        }
    }
    

    【讨论】:

    • 谢谢你,好像我在这里也摸索了基础知识
    猜你喜欢
    • 2011-12-05
    • 2016-07-07
    • 1970-01-01
    • 2016-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多