2

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.

1
  • It's just javac -cp . TetrisPiece, assuming that class has a main() method. Commented Oct 3, 2013 at 23:22

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

Why does one have to compile the files at the same time? I thought that as long as the class file X exists that class Y is dependent on, than that would be sufficient

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.