Code Wont Run, Got Strange Error [closed]

You seem to be mis-understanding the basics of Java syntax. Specifically, you cannot define your class’s members and methods inside main() the way you are attempting to do:

import java.awt.*;
public class Alien {
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        /**
         * The Alien class. 
         */


            public static int ALIEN_HEIGHT = 25;  // you can't put this here
            public static int ALIEN_WIDTH = 15;   // you can't put this here

            private int leftPosition = 0;         // you can't put this here
            private int heightPosition = 0;       // you can't put this here
            //etc

To get this to compile, you need to close main() and delete all the extra } you have at the end of your code:

import java.awt.*;

public class Alien {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
    }

    /**
     * The Alien class. 
     */
    public static int ALIEN_HEIGHT = 25;
    public static int ALIEN_WIDTH = 15;
    //etc

You’ll also need to add some code to main() before your program actually does anything.

I would suggest that before you continue your current program you read some of the excellent tutorials online. A good place to start is The Java™ Tutorials on the oracle website.

Look at the Trails Covering the Basics section and work your way through Getting Started and Learning the Java Language before doing anything else.

Browse More Popular Posts

Leave a Comment