470,815 Members | 1,364 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

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.NoClassDefFoundError: Test

C:\>
public class Test
{
public Test()
{
System.out.println("Test instantiated");
}
public void main(String args[])
{
System.out.println("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
Jul 17 '05 #1
7 4415
Try this!

public class Test
{
public static void Test()
{
System.out.println("Test instantiated");
}
public static void main(String[] args)
{
System.out.println("hello");
Test();
}
}
"Chris Mosser" <cm*****@comcast.net> glsD
:nr********************@comcast.com...
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.NoClassDefFoundError: Test

C:\>
public class Test
{
public Test()
{
System.out.println("Test instantiated");
}
public void main(String args[])
{
System.out.println("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

Jul 17 '05 #2
"Don Shek" <do*****@donshek.com> wrote in message
news:bj*********@imsp212.netvigator.com...
Try this!

public class Test
{
public static void Test()
{
System.out.println("Test instantiated");
}
public static void main(String[] args)
{
System.out.println("hello");
Test();
}
}


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.
Jul 17 '05 #3

"Ryan Stewart" <za****@no.texas.spam.net> wrote in message
news:4q********************@texas.net...
"Don Shek" <do*****@donshek.com> wrote in message
news:bj*********@imsp212.netvigator.com...
Try this!

public class Test
{
public static void Test()
{
System.out.println("Test instantiated");
}
public static void main(String[] args)
{
System.out.println("hello");
Test();
}
}
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.


still nothing....actually, I got a new error:

C:\>java -classpath . Test
Exception in thread "main" java.lang.NoSuchMethodError: 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
Jul 17 '05 #4
"Chris Mosser" <cm*****@comcast.net> wrote in message news:<Zx********************@comcast.com>...
still nothing....actually, I got a new error:

C:\>java -classpath . Test
Exception in thread "main" java.lang.NoSuchMethodError: 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


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) {

}
Jul 17 '05 #5

"Ryan Stewart" <zz******@go.com> wrote in message
news:a1**************************@posting.google.c om...
"Chris Mosser" <cm*****@comcast.net> wrote in message

news:<Zx********************@comcast.com>...
still nothing....actually, I got a new error:

C:\>java -classpath . Test
Exception in thread "main" java.lang.NoSuchMethodError: 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


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) {

}

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...(path, 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
Jul 17 '05 #6
"Chris Mosser" <cm*****@comcast.net> wrote in message
news:Jd********************@comcast.com...
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...(path, 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

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.
Jul 17 '05 #7

"Ryan Stewart" <za****@no.texas.spam.net> wrote in message
news:an********************@texas.net...
"Chris Mosser" <cm*****@comcast.net> wrote in message
news:Jd********************@comcast.com...
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...(path, 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

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.


makes sense..thnx
--
Chris Mosser
Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Bob Bamberg | last post: by
5 posts views Thread by Nathan Bloom | last post: by
2 posts views Thread by Paul | last post: by
12 posts views Thread by Markus Ewald | last post: by
reply views Thread by zfraile | last post: by
reply views Thread by Yelena Varshal via AccessMonster.com | last post: by
7 posts views Thread by Norman Diamond | last post: by
3 posts views Thread by Jim Armstrong | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.