eclipse - 标记“.”上的语法错误,@应在此标记之后
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40000269/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
- Syntax error on token ".", @ expected after this token
提问by cawe011
My Eclipse worked fine a couple of days ago before a Windows update. Now I get error messages whenever I'm trying to do anything in Eclipse. Just a simple program as this will display a bunch of error messages:
几天前,在 Windows 更新之前,我的 Eclipse 运行良好。现在,每当我尝试在 Eclipse 中执行任何操作时,都会收到错误消息。只是一个简单的程序,因为这将显示一堆错误消息:
package lab6;
public class Hellomsg {
System.out.println("Hello.");
}
These are the errors I receive on the same line as I have my
这些是我在同一行收到的错误
"System.out.println":
"Multiple markers at this line
- Syntax error, insert ")" to complete MethodDeclaration
- Syntax error on token ".", @ expected after this token
- Syntax error, insert "Identifier (" to complete MethodHeaderName"
回答by Mureinik
You can't just have statements floating in the middle of classes in Java. You either need to put them in methods:
在 Java 中,不能只在类的中间浮动语句。您要么需要将它们放在方法中:
package lab6;
public class Hellomsg {
public void myMethod() {
System.out.println("Hello.");
}
}
Or in static
blocks:
或者在static
块中:
package lab6;
public class Hellomsg {
static {
System.out.println("Hello.");
}
}
回答by Adam Arold
You can't have statements outside of initializer blocks or methods.
您不能在初始化程序块或方法之外使用语句。
Try something like this:
尝试这样的事情:
public class Hellomsg {
{
System.out.println("Hello.");
}
}
or this
或这个
public class Hellomsg {
public void printMessage(){
System.out.println("Hello.");
}
}
回答by Jens
You have a method call outside of a method which is not possible.
您在方法之外有一个方法调用,这是不可能的。
Correct code Looks like:
正确的代码看起来像:
public class Hellomsg {
public static void main(String[] args) {
System.out.println("Hello.");
}
}