令牌上的Java语法错误....此令牌之后的标识符 [英] Java syntax error on token.... Identifier expected after this token

查看:1614
本文介绍了令牌上的Java语法错误....此令牌之后的标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到Java的语法错误令牌callMe,标识符预期后这个标记错误在我的程序的下面一行:

I am getting Java "Syntax error on token "callMe", Identifier expected after this token" error on below line of my program:

c1.callMe ;

c1.callMe();

class Class2 {
    Class1 c1 = new Class1();
    c1.callMe();
}

public class Class1 {
    public void callMe() {
        System.out.println("I am called!!");
    }
}

请帮我找出原因。提前感谢。

kindly help me out to find the exact cause for this. Thanks in advance.

推荐答案

Class1 c1 = new Class1();
c1.callMe();

必须移动到方法,它不能在类定义级别,没有意义(你的代码何时执行):

Must be moved to a method, it can't be at the class definition level, else it makes no sense (when would your code be executed??):

public class Class2 {
    public void doSomething() {
        Class1 c1 = new Class1();
        c1.callMe();
    }
}

这篇关于令牌上的Java语法错误....此令牌之后的标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆