Very basic question
I am sure you must have come across this problem and I did google for the solution but it dint work
I am doing my school assignment and I try to write a very simple program (just a helloworld to start with)
When I compile with javac no issues. but when I try to run the program(Test) java Test
I get the following error
Exception in thread "main" java.lang.NoClassDefFoundError: test
I found that I need to set the classpath variable but I am not sure where or how or what value to set the classpath at.
If any of you gurus can help that would be great . I have a complex xml parsing program in java to write but am stuck at this simple step. I am beginner in java so sorry if this is too simple
Thanks for your time
I'm fairly new to Java too. In my opinion there is no need to setup class paths to run simple Java programs like 'Hello World' applications. It should work fine. However here are some points you can check.
1. Is the name of your class equal to the name of the file? (your file name should be Test.java only if your class name is Test - I think you got this right since your program gets compiled without errors)
2. Check whether a file called Test.class is generated in the same directory once you compile the program.
3. To run the program issue the command 'java Test' (not 'java Test.class')
4. Have you encapsulated your class in a package? (sometimes this can cause problems when trying to run the application)
If you still want to try setting the class path refer the following article from Sun.
Setting the class path
Hope this helps. All the best.
Your first suggestion worked. I dont know how it got compiled and my file name and class name were different.
Alteast I got the first step correct. I have a complex program ahead of me now. But thanks much for your time and reply