Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
433 views
in Technique[技术] by (71.8m points)

java - - Syntax error on token ".", @ expected after this token

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:

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"
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can't just have statements floating in the middle of classes in Java. You either need to put them in methods:

package lab6;

public class Hellomsg {
    public void myMethod() {
         System.out.println("Hello.");
    }
}

Or in static blocks:

package lab6;

public class Hellomsg {
    static {
         System.out.println("Hello.");
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...