-1

Whenever I compile the java package through this code

 javac -cp ch03.stacks StackDriver.java ArrayStack.java BoundedStackInterface.java StackInterface.java StackUnderflowException.java StackOverflowException.java

It compiles correctly but when I use this command on the driver class

java StackDriver

It responds with this error

Error: Could not find or load main class StackDriver

Why can't I run the main class in the Driver? And what should I do in order to run the main class?

  • Make sure to use semicolon(;) if you are using classpath – Amber Beriwal Feb 11 '16 at 16:58
  • try giving the full path of your obecjt "StackDriver" after java. May be the compile is going to a different directory – user3509208 Feb 11 '16 at 17:08
  • Please provide from what directory you issue the java command. I recommend you to search a little bit prior to asking a question - http://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean. – Seitaridis Feb 11 '16 at 17:19

2 Answers2

0

Figured out that in order to run my Driver I must use this command outside the folder

java ch03/stacks/StackDriver

Which is a bit stupid but I won't dwell on it.

Also discovered a very useful way to compile all of the packages in a folder

javac ch03/stacks/*.java

I will most definitely remember this screw up and learn from it.

-1

JVM cannot find your main() method. You are probably missing this line of code:

public static void main(String args[])  {
//code here
 }