[Solved] Got a very strange syntax error in java


With the commented-out code uncommented, you’re trying to declare a constructor directly within a method. You can’t do that in Java.

// You can't do this
buttonPlay.addListener(new ClickListener(){                   // 1
    public void clicked(InputEvent event, float x, float y) { // 2
        public GameScreen(Create create) {                    // 3
            this.create = create;                             // 3
        }                                                     // 3
    }
});
  1. Instantiating an anonymous class. This is fine.

  2. Implementing a method of that anonymous class (you want to add an @Override there). Also fine.

  3. Declaring a constructor directly within another method. You can’t do that.

1

solved Got a very strange syntax error in java