- Syntax error on token “.”, @ expected after this token

前端 未结 3 1078
心在旅途
心在旅途 2020-12-19 14:06

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 w

相关标签:
3条回答
  • 2020-12-19 14:14

    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.");
        }
    }
    
    0 讨论(0)
  • 2020-12-19 14:34

    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.");
        }
    }
    
    0 讨论(0)
  • 2020-12-19 14:34

    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.");
        }
    }
    
    0 讨论(0)
提交回复
热议问题