please help!

R

rajsundar

whenever i compile my java pgm the class file is created .. but i
could not execute the pgm it gives me a run time error ...

This is the error msg which i get
---------------------------------------------------------------------------------------------------------
"
D:\program files\java\bin>javac test.java



D:\program files\java\bin>java test

Exception in thread "main" java.lang.NoClassDefFoundError: test

Caused by: java.lang.ClassNotFoundException: test

at java.net.URLClassLoader$1.run(URLClassLoader.java:200)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:188)

at java.lang.ClassLoader.loadClass(ClassLoader.java:307)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:
301)

at java.lang.ClassLoader.loadClass(ClassLoader.java:252)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:
320)

Could not find the main class: test. Program will exit.
"
 
L

Lew

rajsundar said:
whenever i [sic] compile my java pgm the class file is created .. but i [sic]
could not execute the pgm it gives me a run time error ...

This is the error msg which i [sic] get
---------------------------------------------------------------------------------------------------------
"
D:\program files\java\bin>javac test.java



D:\program files\java\bin>java test

Exception in thread "main" java.lang.NoClassDefFoundError: test

Caused by: java.lang.ClassNotFoundException: test
...
Could not find the main class: test. Program will exit.
"

Got enough exclamation points there?

The java/bin directory is almost certainly the wrong place to put Java code.
Did you check that 'test.class' was in that directory? Did you define a
'public static void main( String [] args )' method in that class?

Put the Java executables' directory in your PATH and use a different directory
for your projects.

Spell class names with an initial upper-case letter. Variables and methods
are spelled with an initial lower-case letter, except for constant variables.
Use compound words in camel case for names.
<http://java.sun.com/docs/codeconv/index.html>
 
R

Roedy Green

Exception in thread "main" java.lang.NoClassDefFoundError: test

See
http://mindprod.com/jgloss/runerrormessages.html#NOCLASSDEFFOUNDERROR

However, you are making a number of other errors which indicate you
are missing basics. It might be wise to backtrack and get those
nailed.
See http://mindprod.com/jgloss/gettingstarted.html

For example:

Class names must begin with a capital letter. e.g. class Test
Test.java Test.class

You must put your source in a directory tree that reflects the package
name, not the Java system directories.

see http://mindprod.com/jgloss/package.html

Class files must be on the classpath.

See http://mindprod.com/jgloss/classpath.html

Have a look at http://mindprod.com/jgloss/helloworld.html
for how to get a minimal Java program working.
 
L

Lew

Roedy said:
Class files must be on the classpath.

In this particular case, unless the environment variable CLASSPATH has
been set, the way the OP invokes the 'java' command will use the
default classpath of ".".
Class names must begin with a capital letter.
e.g. [sic] class Test Test.java Test.class

Say rather, "should begin with a capital letter". It's a really,
really strong "should", though.

In addition to Roedy's excellent advice,
<http://java.sun.com/docs/books/tutorial/>
is a good starting point.
 
M

markspace

rajsundar said:
D:\program files\java\bin>javac test.java

D:\program files\java\bin>java test


We'll need to see the text of the "test.java" program itself to help
you. Most likely the error is in there.

Lew's comment about not using the java\bin directory was very correct.
Please try to move your programs to your home directory.

C:\Users\raj or something.
 
R

Roedy Green

Say rather, "should begin with a capital letter". It's a really,
really strong "should", though.


In the context of a beginner learning Java I'd say it is a MUST. The
only people who might consider breaking that rule are people
generating Java source code or class files, i.e. not newbies.

Newbies are just confused and mislead if tell them is optional. Out of
laziness, they will then ignore the conventions.

The disadvantages of having them violate the naming conventions far
outweigh the disadvantages of them needlessly conforming to them.

To me it is bit like telling a child not to play with radioactive
materials, liquid mercury or drain cleaner. Yes there are people who
need to do that, but not children.

I used to do public lectures and programming classes every weekend. I
would start by telling people I was going to lie to them on purpose,
to avoid overwhelming them with fine points. Once they had the basics
nailed down, in a second pass we could deal with all the exceptions.

With that power I could train even 7 year olds to write code that
would put to shame most professionals. I taught them it was mandatory
to write the comments first, and what form the comments had to have.

In earlier times, people learned by apprenticeship, and the teacher
felt no compunction about passing on the "right" way to paint, build a
cabinet etc. We need more of that attitude to help newbies quickly
gain a high level of programming skill.
 
A

Arne Vajhøj

Roedy said:
In the context of a beginner learning Java I'd say it is a MUST. The
only people who might consider breaking that rule are people
generating Java source code or class files, i.e. not newbies.

Newbies are just confused and mislead if tell them is optional. Out of
laziness, they will then ignore the conventions.

The problem is that they will not stay newbies forever. They will
turn into Java programmers with some wrong understanding of
basic Java stuff, because someone mislead them when they were
newbies.
I used to do public lectures and programming classes every weekend. I
would start by telling people I was going to lie to them on purpose,
to avoid overwhelming them with fine points. Once they had the basics
nailed down, in a second pass we could deal with all the exceptions.

With that power I could train even 7 year olds to write code that
would put to shame most professionals. I taught them it was mandatory
to write the comments first, and what form the comments had to have.

You did not teach Java (insert name of other language if not Java)
but some language similar to Java.

And it must have been hell to work with those people afterwards
because they came with all types of misunderstandings.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top