Java 在使用smack创建聊天客户端的第一步就卡住了
我开始在smack和eclipse上使用java构建聊天客户端,因此我开始编写以下代码:Java 在使用smack创建聊天客户端的第一步就卡住了,java,xmpp,smack,Java,Xmpp,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"); // Con
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
及
有人能帮我吗?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();
}
}
谢谢,看来我在这里也在摸索基本的东西
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();
}
}