0

So I'm trying to build a 2D game of snake, and I'm almost done. My only issue is that when I try to run the program, I get tis error:

"Exception in thread "main" java.lang.NoClassDefFoundError: Snake (wrong name: snake2/Snake)"

Usually it's just because I'm the the wrong directory or because I typed in the command wrong, but those reasons don't really seem to be the issue. The class with the main method is here: (the logic and 99% of the code is in a second class, also in package snake2)

package snake2;

import javax.swing.JFrame;


public class Snake extends JFrame {

public Snake() {

    add(new Board());

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(320, 340);
    setLocationRelativeTo(null);
    setTitle("Snake");

    setResizable(false);
    setVisible(true);
}

public static void main(String[] args) {
    new Snake();
}
}
Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
TheUnicornCow
  • 49
  • 1
  • 1
  • 5

1 Answers1

2

This is perhaps because you are running it inside the package folder.

Try running it from the folder which contains the snake2 folder (and don't go inside the snake2 folder) and execute the java command as follows:

java snake2.Snake
Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
  • I think real reason is not trying to run from inside package but rather using command java snake2/Snake - but still your command is the correct one – Hurda Mar 23 '13 at 19:28