gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 02:27:49 24 4
gpt4 key购买 nike

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

有人可以帮我吗?

最佳答案

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

关于java - 卡在使用smack制作聊天客户端的第一步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45189413/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com