By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,779 Members | 1,078 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,779 IT Pros & Developers. It's quick & easy.

Help with "main" error

P: n/a

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

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

Chart.class
ChartColourScheme.class
ChartPanel.class
ColorPanel.class
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

Jul 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
news wrote:

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:


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

P: n/a
I use the command line as follows:

c:\j2sdk1.4.2_03\bin\java d:\personal\java-ChartGen\TestChart.class

The full error message is as follows:

Exception in thread "main" java.lang.NoClassDefFoundError:
d:\personal\java-ChartGen\TestChart/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" <cd*****@twu.net> wrote in message
news:MP************************@news.pop4.net...
news wrote:

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:


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

Jul 17 '05 #3

P: n/a

"news" <j@j.cm> wrote in message
news:uF*****************@nwrdny03.gnilink.net...
I use the command line as follows:

c:\j2sdk1.4.2_03\bin\java d:\personal\java-ChartGen\TestChart.class

The full error message is as follows:

Exception in thread "main" java.lang.NoClassDefFoundError:
d:\personal\java-ChartGen\TestChart/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.


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_03\bin\java d:\personal\java-ChartGen\TestChart

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\bin

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

d: <ENTER>
cd d:\personal\java-ChartGen\TestChart <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.TestChart

I hope this helps.

Anthony Borla

P.S.

The following link may be of help:

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

Jul 17 '05 #4

P: n/a
On Sun, 14 Dec 2003 05:03:25 GMT, "Anthony Borla"
<aj*****@bigpond.com> wrote or quoted :
Exception in thread "main" java.lang.NoClassDefFoundError:


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

P: n/a

"Roedy Green" <lo**********************************@mindprod.com > wrote in
message news:uq********************************@4ax.com...
On Sun, 14 Dec 2003 05:03:25 GMT, "Anthony Borla"
<aj*****@bigpond.com> wrote or quoted :
Exception in thread "main" java.lang.NoClassDefFoundError:


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


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

Cheers,

Anthony Borla
Jul 17 '05 #6

P: n/a
In article <uF*****************@nwrdny03.gnilink.net>, "news" <j@j.cm>
wrote:
c:\j2sdk1.4.2_03\bin\java d:\personal\java-ChartGen\TestChart.class


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

P: n/a
news wrote:
I use the command line as follows:

c:\j2sdk1.4.2_03\bin\java d:\personal\java-ChartGen\TestChart.class

The full error message is as follows:

Exception in thread "main" java.lang.NoClassDefFoundError:
d:\personal\java-ChartGen\TestChart/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.


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.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.