Help with "main" error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • news

    Help with "main" error


    I am pretty new to Java and I just install the JDK1.4.2 03
    I am getting an error when I run the class file TestChart.class with the
    java.exe:

    Exception in thread "main" java.lang.NoCla ssDefFoundError :

    I have several class files in the directory d:\personal\jav a-ChartGen

    Chart.class
    ChartColourSche me.class
    ChartPanel.clas s
    ColorPanel.clas s
    TestChart.class
    TestIt.class

    All these files are for the program.
    Can some one help me why is this happening?? Is there something I can do
    that I am missing???
    I tried using the -CLASSPATH to direct it to the same directory but still
    with the same error.

    Please help me. Thank you



  • Chris Smith

    #2
    Re: Help with "main&quot ; error

    news wrote:[color=blue]
    >
    > I am pretty new to Java and I just install the JDK1.4.2 03
    > I am getting an error when I run the class file TestChart.class with the
    > java.exe:[/color]

    What's your command line? What is the full error message? We can't
    read your mind, or your screen; and withholding important information
    like that makes it very difficult to answer your question.

    --

    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation

    Comment

    • news

      #3
      Re: Help with "main&quot ; error

      I use the command line as follows:

      c:\j2sdk1.4.2_0 3\bin\java d:\personal\jav a-ChartGen\TestCh art.class

      The full error message is as follows:

      Exception in thread "main" java.lang.NoCla ssDefFoundError :
      d:\personal\jav a-ChartGen\TestCh art/class


      I thought it may be the CLASSPATH, but all my class files are located in the
      same folder and I used the switch -classpath but the same error comes up.



      "Chris Smith" <[email protected] t> wrote in message
      news:MPG.1a4566 9187e98ca498980 [email protected] ...[color=blue]
      > news wrote:[color=green]
      > >
      > > I am pretty new to Java and I just install the JDK1.4.2 03
      > > I am getting an error when I run the class file TestChart.class with the
      > > java.exe:[/color]
      >
      > What's your command line? What is the full error message? We can't
      > read your mind, or your screen; and withholding important information
      > like that makes it very difficult to answer your question.
      >
      > --
      > www.designacourse.com
      > The Easiest Way to Train Anyone... Anywhere.
      >
      > Chris Smith - Lead Software Developer/Technical Trainer
      > MindIQ Corporation[/color]


      Comment

      • Anthony Borla

        #4
        Re: Help with &quot;main&quot ; error


        "news" <[email protected]> wrote in message
        news:uFRCb.1839 $D66.1494@nwrdn y03.gnilink.net ...[color=blue]
        > I use the command line as follows:
        >
        > c:\j2sdk1.4.2_0 3\bin\java d:\personal\jav a-ChartGen\TestCh art.class
        >
        > The full error message is as follows:
        >
        > Exception in thread "main" java.lang.NoCla ssDefFoundError :
        > d:\personal\jav a-ChartGen\TestCh art/class
        >
        > I thought it may be the CLASSPATH, but all my class files
        > are located in the same folder and I used the switch -classpath
        > but the same error comes up.
        >[/color]

        You shouldn't be using the '.class' extension on the command-line. The JVM
        expects a classname, so you would be better off doing:

        c:\j2sdk1.4.2_0 3\bin\java d:\personal\jav a-ChartGen\TestCh art

        Alternatively:

        * Set your PATH [similar to setting the CLASSPATH as
        I earlier described] to include the location of the J2SDK
        binaries

        set PATH=%path%;c:\ j2sdk1.4.2_03\b in

        * Now you can just change directory to the '.class'
        file location:

        d: <ENTER>
        cd d:\personal\jav a-ChartGen\TestCh art <ENTER>

        * You may now invoke the application thus:

        java -cp . TestChart

        * Of course, if your application is 'packaged up', you may
        need to do:

        d: <ENTER>
        cd \ <ENTER>

        and invoke the application thus:

        java personal.java-ChartGen.TestCh art

        I hope this helps.

        Anthony Borla

        P.S.

        The following link may be of help:





        Comment

        • Roedy Green

          #5
          Re: Help with &quot;main&quot ; error

          On Sun, 14 Dec 2003 05:03:25 GMT, "Anthony Borla"
          <ajborla@bigpon d.com> wrote or quoted :
          [color=blue][color=green]
          >> Exception in thread "main" java.lang.NoCla ssDefFoundError :[/color][/color]

          see http://mindprod.com/jgloss/errormess...SDEFFOUNDERROR

          --
          Canadian Mind Products, Roedy Green.
          Coaching, problem solving, economical contract programming.
          See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

          Comment

          • Anthony Borla

            #6
            Re: Help with &quot;main&quot ; error


            "Roedy Green" <look-at-the-website-for-actual-Roedy@mindprod. com> wrote in
            message news:uqsntvko3m h94p1f59v59kl6p [email protected] om...[color=blue]
            > On Sun, 14 Dec 2003 05:03:25 GMT, "Anthony Borla"
            > <ajborla@bigpon d.com> wrote or quoted :
            >[color=green][color=darkred]
            > >> Exception in thread "main" java.lang.NoCla ssDefFoundError :[/color][/color]
            >
            > see http://mindprod.com/jgloss/errormess...SDEFFOUNDERROR
            >[/color]

            Well, I got the web site part right ;) !

            Cheers,

            Anthony Borla


            Comment

            • Mark Haase

              #7
              Re: Help with &quot;main&quot ; error

              In article <uFRCb.1839$D66 .1494@nwrdny03. gnilink.net>, "news" <[email protected]>
              wrote:
              [color=blue]
              > c:\j2sdk1.4.2_0 3\bin\java d:\personal\jav a-ChartGen\TestCh art.class[/color]

              When you use the java command, you don't specify ".class"--it is assumed
              and the period makes java think its looking for a class inside of a
              package, which you don't have.

              You also don't have to specify full paths like that. (Maybe you're just
              doing it in frustration at not getting it to work).

              Just cd to the directory containing your classes and type

              java TestChart

              --
              |\/| /| |2 |<
              mehaase(at)sas( dot)upenn(dot)e du

              Comment

              • Chris Smith

                #8
                Re: Help with &quot;main&quot ; error

                news wrote:[color=blue]
                > I use the command line as follows:
                >
                > c:\j2sdk1.4.2_0 3\bin\java d:\personal\jav a-ChartGen\TestCh art.class
                >
                > The full error message is as follows:
                >
                > Exception in thread "main" java.lang.NoCla ssDefFoundError :
                > d:\personal\jav a-ChartGen\TestCh art/class
                >
                >
                > I thought it may be the CLASSPATH, but all my class files are located in the
                > same folder and I used the switch -classpath but the same error comes up.[/color]

                You've got a few responses, but I don't think they clearly explain the
                issue, so I'll pop in. The Java VM expects a class name as it argument.
                A class name is:

                1. NOT a filename for a class file.
                2. NOT the same as a filename minus the extension.

                Instead of any of the above, it's a fully qualified class name. That
                means the identifier that you put after the 'class' keyword in the
                source file where you wrote the class, prefixed by the dot-delimited
                string of identifiers after your 'package' keyword, if there is one.
                Any "path" information shouldn't be there, period.

                The source of confusion is that there are also a few rules that relate
                the name of a class to how it's found by the VM. Those are incidental.
                The classpath (set by an environment variable or command line option, or
                various other implicit rules) determines at a basic level where the
                class is found. The class name is the parameter, and it doesn't
                duplicate the purpose of the classpath.

                For this reason, I think it's helpful to say "use the class name, not a
                file name" and that it's potentially quite confusing to say "leave off
                the extension". After all, your command would still not have worked
                even without the extension. Why? Because it's still not the class
                name.

                --

                The Easiest Way to Train Anyone... Anywhere.

                Chris Smith - Lead Software Developer/Technical Trainer
                MindIQ Corporation

                Comment

                Working...