473,394 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 4506
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> ¼¶¼g©ó¶l¥ó·s»D
: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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Bob Bamberg | last post by:
Hello All, I have been trying without luck to get some information on debugging the Runtime Error R6025 - Pure Virtual Function Call. I am working in C++ and have only one class that is derived...
5
by: Nathan Bloom | last post by:
Hi, I have a secured database that runs fine on the computer the database is installed on. I have several workstations with access runtime installed that also need access to the database. ...
2
by: Paul | last post by:
I'm hoping someone can help me with the problem. I have a database where the default value for a date field in a table is =date() This works perfectly in my table and on my form. But when I...
12
by: Markus Ewald | last post by:
I'm just experimenting around with the VisualC++ 2005 Express Edition Beta and found some strange behavior for which I can't seem to find a workaround. What I've done is set up two static library...
0
by: Kirk | last post by:
I'm trying to use a Web Service to be a Remoting client of an existing ..NET 2.0 server. But I get the following error when I try to use System.Runtime.Remoting.Channels.Http in my WebService. ...
0
by: zfraile | last post by:
I'm getting this error from the JIT compiler at runtime, but only on my boss' machine, not my development machine. I believe the error is generated from a call to an Excel object, but I can't tell...
0
by: Yelena Varshal via AccessMonster.com | last post by:
Hello We have a shortcut for our MS ACCESS application that uses a /Runtime switch because we may have some users that use Runtime. The application worked fine in Access 2000 and was tested with...
7
by: Norman Diamond | last post by:
A project depends on VC runtime from Visual Studio 2005 SP1, and DotNet Framework 2. Options are set in the setup project properties, so if these two dependencies are not already installed then...
3
by: Jim Armstrong | last post by:
Hello all - This is driving me crazy. I have a table called tblClients - very simple, has the following fields: taxID (PK) ClientName SalesName The main form of my application allows a...
1
by: BL3WC | last post by:
Hi, I'd created a MDE under Access 2003. It is now under testing stage. Some of the users will use Access 2003 runtime and some will use Access 2007 runtime to run this MDE. I installed the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.