Exception in thread "main"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tiyaramunna
    New Member
    • Aug 2008
    • 3

    Exception in thread "main"

    I am trying to configure my system with Java program just to practice on the coding....when i compile a test.java program i am able to see the class file but i cant run the program ... I am getting the following error
    Exception in thread "main" java.lang.NoCla ssDefFoundError : test
    Caused by: java.lang.Class NotFoundExcepti on: test
    at java.net.URLCla ssLoader$1.run( Unknown Source)
    at java.security.A ccessController .doPrivileged(N ative Method)
    at java.net.URLCla ssLoader.findCl ass(Unknown Source)
    at java.lang.Class Loader.loadClas s(Unknown Source)
    at sun.misc.Launch er$AppClassLoad er.loadClass(Un known Source)
    at java.lang.Class Loader.loadClas s(Unknown Source)
    at java.lang.Class Loader.loadClas sInternal(Unkno wn Source)
    i know the path is not set right could anyone please help me with setting the path right...java resides in c drive as well as inside the program files which folder should i refer to while setting the path :(
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Where (which folder) is test.class and from where are you running the java test command?

    Comment

    • RamananKalirajan
      Contributor
      • Mar 2008
      • 608

      #3
      This may be a solution for your problem. Copy the path of the JDk upto bin
      ex: c:\program files\jdk1.5\bi n. Go to the control panel in that systems. In Systems click Advanced Tab. In that Environment Variables. There u can see to large boxes 1 for your variables and the other for the system variables.

      Click new in the top one
      It will ask for Variable Name and Variable path.

      In Variable Name enter the column as "path"(with out quotes)
      then in variable path paste the Jdk path you copied & append a semicolon to it(";").
      press ok. After that open ur command prompt. Enter echo %path% run this command. Your java path will be set the environment so that u need not to set path every time while u run the java program you can run the program any were.

      Regards
      Ramanan Kalirajan

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by RamananKaliraja n
        This may be a solution for your problem. Copy the path of the JDk upto bin
        ex: c:\program files\jdk1.5\bi n. Go to the control panel in that systems. In Systems click Advanced Tab. In that Environment Variables. There u can see to large boxes 1 for your variables and the other for the system variables.

        Click new in the top one
        It will ask for Variable Name and Variable path.

        In Variable Name enter the column as "path"(with out quotes)
        then in variable path paste the Jdk path you copied & append a semicolon to it(";").
        press ok. After that open ur command prompt. Enter echo %path% run this command. Your java path will be set the environment so that u need not to set path every time while u run the java program you can run the program any were.

        Regards
        Ramanan Kalirajan
        The problem is not with the path, it's with the classpath. Java path != classpath.

        Comment

        • RamananKalirajan
          Contributor
          • Mar 2008
          • 608

          #5
          Originally posted by r035198x
          The problem is not with the path, it's with the classpath. Java path != classpath.
          see if you set the path like that and work. It will automatically take care of the class path also. Just try it out. You dont need to give or set path again and again when u run the program.

          Regards
          Ramanan Kalirajan

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by RamananKaliraja n
            see if you set the path like that and work. It will automatically take care of the class path also. Just try it out. You dont need to give or set path again and again when u run the program.

            Regards
            Ramanan Kalirajan
            Setting the path does not automatically set the classpath. The path is the location of the java tools. The classpath is the location of classes required to run another class. If the path is not set you will get a command not found system message when trying to compile the .java.

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by RamananKaliraja n
              see if you set the path like that and work. It will automatically take care of the class path also. Just try it out. You dont need to give or set path again and again when u run the program.
              Please don't confuse the OP. The path variable is used by the OS: it searches
              the directories in the path variable for executable files such as java.exe and
              javac.exe.

              The classpath variable is purely a Java thing: it contains a list of directories
              and/or jar files that are searched by the class loaders when they need to load a
              class.

              kind regards,

              Jos

              Comment

              • tiyaramunna
                New Member
                • Aug 2008
                • 3

                #8
                Originally posted by r035198x
                Where (which folder) is test.class and from where are you running the java test command?
                i run the programs from the command prompt...and my test.class file is in d:\java folder

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #9
                  Read the top article of this forum; it's named "Read This First" and follow the
                  link that tells you all about the classpath.

                  kind regards,

                  Jos

                  Comment

                  • tiyaramunna
                    New Member
                    • Aug 2008
                    • 3

                    #10
                    Originally posted by JosAH
                    Read the top article of this forum; it's named "Read This First" and follow the
                    link that tells you all about the classpath.

                    kind regards,

                    Jos
                    thank you ...appreciate all the help given.....the programs are running fine now great appreciate all the assistance.

                    Regards
                    Tiyara

                    Comment

                    Working...