Results 1 to 3 of 3
  1. #1
    gvi
    gvi is offline Member
    Join Date
    Oct 2007
    Posts
    6
    Rep Power
    0

    Default 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
    G

  2. #2
    hiranya is offline Member
    Join Date
    Jun 2007
    Location
    Colombo, Sri Lanka
    Posts
    32
    Rep Power
    0

    Default

    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.

    Regards,
    Hiranya

  3. #3
    gvi
    gvi is offline Member
    Join Date
    Oct 2007
    Posts
    6
    Rep Power
    0

    Default

    Thanks hiranya

    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

    G

Similar Threads

  1. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 09:49 AM
  2. Basic question about EJB
    By javaplus in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 07-15-2008, 06:44 PM
  3. Basic Applet
    By jkswebsite in forum Java Applets
    Replies: 4
    Last Post: 01-13-2008, 10:14 PM
  4. basic question about files
    By oregon in forum New To Java
    Replies: 1
    Last Post: 08-05-2007, 03:34 AM
  5. help with basic example
    By fred in forum New To Java
    Replies: 1
    Last Post: 07-20-2007, 06:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •