runtime error

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

    runtime error

    K... I'm a java beginner and I took a few months off and now I seem to be
    having a brain fart or something. The following is a simple class I created
    because I was having trouble running a chat server class that was written
    for school. I get the same error on both class when I try to run them.
    Here is the error:

    C:\>javac Test.java

    C:\>java Test
    Exception in thread "main" java.lang.NoCla ssDefFoundError : Test

    C:\>


    public class Test
    {
    public Test()
    {
    System.out.prin tln("Test instantiated");
    }
    public void main(String args[])
    {
    System.out.prin tln("hello");
    //new Test();
    }
    }

    I verified that the .class and .java files were present and in the correct
    location .... C:\

    so can anyone point out the small something that I am missing
    here??????????? ??????????
    --
    Chris Mosser


  • Don Shek

    #2
    Re: runtime error

    Try this!

    public class Test
    {
    public static void Test()
    {
    System.out.prin tln("Test instantiated");
    }
    public static void main(String[] args)
    {
    System.out.prin tln("hello");
    Test();
    }
    }
    "Chris Mosser" <cmosser@comcas t.net> ¼¶¼g©ó¶l¥ó·s»D
    :nridnZFXSKkHL8 OiXTWJiw@comcas t.com...[color=blue]
    > K... I'm a java beginner and I took a few months off and now I seem to be
    > having a brain fart or something. The following is a simple class I[/color]
    created[color=blue]
    > because I was having trouble running a chat server class that was written
    > for school. I get the same error on both class when I try to run them.
    > Here is the error:
    >
    > C:\>javac Test.java
    >
    > C:\>java Test
    > Exception in thread "main" java.lang.NoCla ssDefFoundError : Test
    >
    > C:\>
    >
    >
    > public class Test
    > {
    > public Test()
    > {
    > System.out.prin tln("Test instantiated");
    > }
    > public void main(String args[])
    > {
    > System.out.prin tln("hello");
    > //new Test();
    > }
    > }
    >
    > I verified that the .class and .java files were present and in the correct
    > location .... C:\
    >
    > so can anyone point out the small something that I am missing
    > here??????????? ??????????
    > --
    > Chris Mosser
    >
    >[/color]


    Comment

    • Ryan Stewart

      #3
      Re: runtime error

      "Don Shek" <donshek@donshe k.com> wrote in message
      news:bjn9o3$men [email protected] gator.com...[color=blue]
      > Try this!
      >
      > public class Test
      > {
      > public static void Test()
      > {
      > System.out.prin tln("Test instantiated");
      > }
      > public static void main(String[] args)
      > {
      > System.out.prin tln("hello");
      > Test();
      > }
      > }[/color]

      That's not exactly what he's trying to do, and when this program prints
      "Test instantiated", it hasn't actually been instantiated. Chris, your
      problem may be the classpath. It's the environment variable that tells java
      where to look for classes. Try this:

      java -classpath . Test

      If that works, you just need to set your classpath variable to whatever
      directory you will be working in.


      Comment

      • Chris Mosser

        #4
        Re: runtime error


        "Ryan Stewart" <[email protected] s.spam.net> wrote in message
        news:4qudnZyCWr bBDMKiRTvUrg@te xas.net...[color=blue]
        > "Don Shek" <donshek@donshe k.com> wrote in message
        > news:bjn9o3$men [email protected] gator.com...[color=green]
        > > Try this!
        > >
        > > public class Test
        > > {
        > > public static void Test()
        > > {
        > > System.out.prin tln("Test instantiated");
        > > }
        > > public static void main(String[] args)
        > > {
        > > System.out.prin tln("hello");
        > > Test();
        > > }
        > > }[/color]
        >
        > That's not exactly what he's trying to do, and when this program prints
        > "Test instantiated", it hasn't actually been instantiated. Chris, your
        > problem may be the classpath. It's the environment variable that tells[/color]
        java[color=blue]
        > where to look for classes. Try this:
        >
        > java -classpath . Test
        >
        > If that works, you just need to set your classpath variable to whatever
        > directory you will be working in.
        >
        >[/color]

        still nothing....actu ally, I got a new error:

        C:\>java -classpath . Test
        Exception in thread "main" java.lang.NoSuc hMethodError: main

        just occurred to me that the last time I ran a console program was before I
        installed the JBuilder enterprise demo. I recently uninstalled it...could
        this have changed some global something or other.. or should I just
        reinstall the JDK, because I used to have no problem running a console
        program like this.. I never even had to use the -classpath(-cp actually)
        unless I was running from a jar.

        anymore idea's to try before I reinstall?????? ???

        thnx
        chris


        Comment

        • Ryan Stewart

          #5
          Re: runtime error

          "Chris Mosser" <cmosser@comcas t.net> wrote in message news:<Zx6dnUaCn 7gQTMKiXTWJhw@c omcast.com>...[color=blue]
          > still nothing....actu ally, I got a new error:
          >
          > C:\>java -classpath . Test
          > Exception in thread "main" java.lang.NoSuc hMethodError: main
          >
          > just occurred to me that the last time I ran a console program was before I
          > installed the JBuilder enterprise demo. I recently uninstalled it...could
          > this have changed some global something or other.. or should I just
          > reinstall the JDK, because I used to have no problem running a console
          > program like this.. I never even had to use the -classpath(-cp actually)
          > unless I was running from a jar.
          >
          > anymore idea's to try before I reinstall?????? ???
          >
          > thnx
          > chris[/color]

          Ack, sorry I missed it the first time. You have to have a "static" in
          your main method declaration, like so:

          public static void main(String[] args) {

          }

          Comment

          • Chris Mosser

            #6
            Re: runtime error


            "Ryan Stewart" <[email protected] m> wrote in message
            news:a12726d3.0 309110541.4959b [email protected] gle.com...[color=blue]
            > "Chris Mosser" <cmosser@comcas t.net> wrote in message[/color]
            news:<Zx6dnUaCn 7gQTMKiXTWJhw@c omcast.com>...[color=blue][color=green]
            > > still nothing....actu ally, I got a new error:
            > >
            > > C:\>java -classpath . Test
            > > Exception in thread "main" java.lang.NoSuc hMethodError: main
            > >
            > > just occurred to me that the last time I ran a console program was[/color][/color]
            before I[color=blue][color=green]
            > > installed the JBuilder enterprise demo. I recently uninstalled[/color][/color]
            it...could[color=blue][color=green]
            > > this have changed some global something or other.. or should I just
            > > reinstall the JDK, because I used to have no problem running a console
            > > program like this.. I never even had to use the -classpath(-cp actually)
            > > unless I was running from a jar.
            > >
            > > anymore idea's to try before I reinstall?????? ???
            > >
            > > thnx
            > > chris[/color]
            >
            > Ack, sorry I missed it the first time. You have to have a "static" in
            > your main method declaration, like so:
            >
            > public static void main(String[] args) {
            >
            > }[/color]


            hmm..odd. I added the static part as you suggested...and it worked. So I
            went back and looked at my original chat server class and it already had
            static in the main function. I was playing around with my environment
            variables...(pa th, classpath...etc ) and I actually think that that did it,
            ... but it is good to know that static is required on the "main" function

            thnx

            Chris


            Comment

            • Ryan Stewart

              #7
              Re: runtime error

              "Chris Mosser" <cmosser@comcas t.net> wrote in message
              news:Jd6cnQexiP 8tjPyiXTWJhg@co mcast.com...[color=blue]
              > hmm..odd. I added the static part as you suggested...and it worked. So I
              > went back and looked at my original chat server class and it already had
              > static in the main function. I was playing around with my environment
              > variables...(pa th, classpath...etc ) and I actually think that that did it,
              > .. but it is good to know that static is required on the "main" function
              >
              > thnx
              >
              > Chris
              >
              >[/color]
              Well, think about it. Non-static classes can't be accessed without first
              creating an instance of the class. Therefore if your main class isn't
              static, it is inaccessible.


              Comment

              • Chris Mosser

                #8
                Re: runtime error


                "Ryan Stewart" <[email protected] s.spam.net> wrote in message
                news:anmdnfaXuI RApvyiRTvUpQ@te xas.net...[color=blue]
                > "Chris Mosser" <cmosser@comcas t.net> wrote in message
                > news:Jd6cnQexiP 8tjPyiXTWJhg@co mcast.com...[color=green]
                > > hmm..odd. I added the static part as you suggested...and it worked. So[/color][/color]
                I[color=blue][color=green]
                > > went back and looked at my original chat server class and it already had
                > > static in the main function. I was playing around with my environment
                > > variables...(pa th, classpath...etc ) and I actually think that that did[/color][/color]
                it,[color=blue][color=green]
                > > .. but it is good to know that static is required on the "main" function
                > >
                > > thnx
                > >
                > > Chris
                > >
                > >[/color]
                > Well, think about it. Non-static classes can't be accessed without first
                > creating an instance of the class. Therefore if your main class isn't
                > static, it is inaccessible.
                >
                >[/color]

                makes sense..thnx


                --
                Chris Mosser


                Comment

                Working...