jcarter31792
jcarter31792

Reputation: 1

Error Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>

New Java user here with a possibly stupid question. Please bear with me...

Here is my code:

package javagame;

import java.awt.Graphics;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;

public class JavaGame extends JFrame {
    int x, y;

    public class AL extends KeyAdapter {

        public void keyPressed(KeyEvent e) {
            int keyCode = e.getKeyCode();
            if (keyCode == e.VK_LEFT) {
                x--;

            }
            if (keyCode == e.VK_RIGHT) {
                x++;

            }
            if (keyCode == e.VK_UP) {
                y--;

            }
            if (keyCode == e.VK_DOWN) {
                y++;

            }
        }

        public void keyReleased(KeyEvent e) {

        }

    }

    public JavaGame() {
        addKeyListener(newAL());
        setTitle("Java Game");
        setSize(250, 250);
        setResizable(false);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        x = 150;
        y = 150;
    }

    public void paint(Graphics g) {
        g.fillOval(x, y, 15, 15);
        repaint();
    }

    public static void main(String[] args) {
        new JavaGame();
    }

}

Now when I try to run it, the build is successful but it still pops the error:

cannot find symbol
symbol: method newAL()
location class JavaGame

any ideas?

Upvotes: 0

Views: 1743

Answers (1)

hsun324
hsun324

Reputation: 549

You are trying to call a function newAL which you do not have. Use:

new AL()

The new keyword specifies that you want to create a new instance of the AL class.

Upvotes: 3

Related Questions