【问题标题】:Syntax error on token ";", invalid AssignmentOperator令牌“;”上的语法错误,无效的 AssignmentOperator
【发布时间】:2014-09-18 21:58:44
【问题描述】:
private List<String> tokens = new ArrayList<String>();

我有一些代码,但这给了我一个错误。

我使用 Eclipse,它在 字符下方显示了一个红色下划线。我不知道为什么。一切似乎都很好。这是整个代码:

public class Analyze {

    protected String text = null;

    public List<String> tokens = new ArrayList<String>(); // Error is right here.

    this.tokenize();

    public Analyze(String txt) {
        // This is the constructor. I will call the class outside with a variable just like method. Just like: Analyze aText = new Analyze("Some texts here.");
        // Then I will call the tokens variable inside the class. (Or am I just doing it wrong?)

        this.text = txt;
    }

    private List<String> tokenize() {
        // Some codes that changes the value of "tokens" variable.
    }
}

我在网上和这个平台上看了一下,我一般发现一些逻辑运算符如 、= 等会导致这个问题,但不是 ;

其他编辑

当我像这样更改这些行的位置时:

public List<String> tokens = new ArrayList<String>();
protected String text = null; // Then error seems right here.

【问题讨论】:

  • this.Analyze();这是无效行
  • 正确。那条线需要在某种方法中。另外,你的意思是在那里发生?该方法返回一个值,但您不使用它做任何事情。
  • // Some Codes 区域改变私有tokens变量的值并返回。 (其实我只是看到看起来很傻,我会编辑代码。)

标签: java eclipse assignment-operator


【解决方案1】:

您的问题出在this.Analyze();。它应该在某个方法中。

虽然目前还不清楚这条线应该做什么。

【讨论】:

    【解决方案2】:

    你不能在当前位置有this.tokenize();

    你可以这样写,但这也没有任何作用,因为它返回数组列表

    public Analyze(String txt) {
        this.text = txt;
        this.tokenize();
    }
    

    【讨论】:

    • 我刚刚编辑了代码。我公开了 tokens,以便我可以在课外接触到它。
    • 方法调用的位置正确。在静态块中之前,您不能进行这样的方法调用
    猜你喜欢
    • 2020-10-25
    • 2019-02-24
    • 2016-10-18
    • 1970-01-01
    • 1970-01-01
    • 2021-07-21
    • 2013-07-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多