Will Hua
Will Hua

Reputation: 1748

Java Cannot Find Class File

I'm not sure what is going wrong here. I have to write a Tetris program based off of a Skeleton given by my teacher for school. The current class that I am implmenting is called "TetrisPiece" and the abstract class being extended is called "Piece." For some reason I cannot compile my code because it cannot located the Piece class.

I have Piece.java and TetrisPiece.java in the same folder. The structure is:

/src
    /TetrisPiece.java
    /Piece.java
    /Piece.class

I type

javac Piece.java

and it compiles correctly, then I type

javac -cp . TetrisPiece.java

and it results in a compiler error (I have to type -cp . because I messed up my classpath somehow and Java can't find the current directory). I looked through a couple similar StackOverflow Questions and they did not have an answer to this. If the information I provide is not detailed enough (which I assume it isn't) please tell me what else I should provide to give an adequate answer.

Upvotes: 2

Views: 9293

Answers (1)

John Kugelman
John Kugelman

Reputation: 361565

You need to compile the files at the same time:

javac Piece.java TetrisPiece.java

Then, assuming TetrisPiece has a main() method, you can run the program with:

java TetrisPiece

Upvotes: 2

Related Questions