卡在使用smack制作聊天客户端的第一步



我开始在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

有人可以在这里帮助我吗?

U 不能将语句(如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();
}
}

最新更新