【问题标题】:Eclipse gives error message on class variable declarations?Eclipse 在类变量声明中给出错误消息?
【发布时间】:2015-01-01 19:09:36
【问题描述】:

我正在用java练习网络,我打算通过SocketChannel发送一个文件,主机和端口由用户指定。但是,当我声明变量时,Eclipse 会给出错误消息:

“令牌语法错误,删除这些令牌” 编辑:(此错误消息在端口和主机声明旁边弹出)

这是我的代码:

public int port;
public String host;

public class Client {

public static void main (String[] args) {

    System.out.print("Enter host/ip: ");
    Scanner inputHost = new Scanner(System.in);
    host = inputHost.next();

    System.out.print("Enter port: ");
    Scanner inputPort = new Scanner(System.in);
    port = inputPort.nextInt();




    Client client = new Client();
    SocketChannel channel = client.createChannel();
    client.sendFile(channel);

【问题讨论】:

  • posthost 变量都需要在 Client 类的范围内声明。
  • 哦,对不起,愚蠢的错误

标签: java eclipse network-programming socketchannel


【解决方案1】:

端口和主机变量需要在类变量中定义,并且根据它们在静态方法 main 中的使用情况,需要将它们声明为静态。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-22
    • 1970-01-01
    相关资源
    最近更新 更多