Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Java woes when running anything

1 view
Skip to first unread message

Allan Bruce

unread,
Nov 6, 2003, 10:11:37 AM11/6/03
to
Hi there,

I am very new to java and am liking it so far. I had everything working,
using just notepad and dos to compile/run my code.

Last night, I found that nothing would run, *.java files would compile
without a problem but when I tried to run it I got an error

Exception in thread "main" java.lang.NoClassDefFoundError: ClientSide/class

I tried to compile/run from NetBeans, and again compiles fine without error
but I get a lot of errors when trying to run:

java.lang.NoClassDefFoundError: Declan/ClientSide (wrong name: ClientSide)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Exception in thread "main"

I know what I am trying to compile is fine as it runs on my machine at work
with the same dev tools. I transfered my .class files compiled on my home
machine (the one with the problems) to my work machine (the one that works
fine) and I get the same errors, which makes me think its a compiler issue.
I then transfered the .class files compiled on my work machine to my home
machine but I still get the errors, so that stumped me.
Perhaps it is the packages that cant be correct on my home machine?

Has anybody experienced this in the past? Better still, can somebody tell me
how to remedy this? I have tried removing all java components from my home
machine, rebooting, then re-installing but still no luck. I have installed
the j2sdk1.4.2 and the j2re1.4.2 both from sun. I run WinXP SP1 on an
Athlon machine (if its any help)

Many thanks
Allan


Chris Smith

unread,
Nov 6, 2003, 11:00:08 AM11/6/03
to
These are two different problems. I'll take each in turn:

Allan Bruce wrote:
> Exception in thread "main" java.lang.NoClassDefFoundError: ClientSide/class

You are confused about the usage of the Java VM. The correct usage is:

java <class name>

You were instead trying to use:

java <class file name/path>

That isn't the way things work, though. You give the Java VM the name
of a class to start with, and it finds the corresponding class file
through all the usual means (the classpath, the boot classpath, the
extensions directory, etc.). So, since you've written a class called
'ClientSide', it needs to be run as 'java ClientSide', NOT
ClientSide.class.

In Java class names, a period indicates a package, and the latter
command is causing the VM to look for a class called 'class' in a
PACKAGE called 'ClientSide'. It's not surprising that it can't find
such a thing.

Now, on to the next problem:

> java.lang.NoClassDefFoundError: Declan/ClientSide (wrong name: ClientSide)

Here, you've got a mismatch between the locations of your files and the
packages of the classes that they contain. You've written a class
called ClientSide, and then tried to run it as if it were a class called
'Declan.ClientSide'. Apparently, you've also moved the compiled class
file into a directory called Declan. But you haven't changed the
package declaration in the source file.

A class's package and the location of its class file must match. Either
move the class back to its original position and run it from the default
package, or change it package declaration to the package you want it to
reside in.

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

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Allan Bruce

unread,
Nov 6, 2003, 11:09:46 AM11/6/03
to
Oh dear me, I am sorry! It works now from the command line, but I am still
having problems with NetBeans, but I guess this is off-topic here.
Thanks
Allan


"Chris Smith" <cds...@twu.net> wrote in message
news:MPG.1a141df5b...@news.pop4.net...

Steve W. Jackson

unread,
Nov 6, 2003, 11:26:25 AM11/6/03
to
In article <bodo8i$6q8$1...@news.freedom2surf.net>,
"Allan Bruce" <all...@TAKEAWAYf2s.com> wrote:

>:Hi there,

Refer to <http://java.sun.com/docs/books/tutorial/getStarted/cupojava/>.

That's always a good place to start, since it has a bare-bones tutorial
for compiling and running your first "Hello World" program.

The short answer to your specific problem is that you're trying to
execute this command:

java ClientSide.class

You don't use the class file name here, you use the class name.
Instead, try using this:

java ClientSide

All this assuming, of course, that everything else is set up correctly.

= Steve =
--
Steve W. Jackson
Montgomery, Alabama

Allan Bruce

unread,
Nov 6, 2003, 11:54:48 AM11/6/03
to
> Refer to <http://java.sun.com/docs/books/tutorial/getStarted/cupojava/>.
>
> That's always a good place to start, since it has a bare-bones tutorial
> for compiling and running your first "Hello World" program.
>
> The short answer to your specific problem is that you're trying to
> execute this command:
>
> java ClientSide.class
>
> You don't use the class file name here, you use the class name.
> Instead, try using this:
>
> java ClientSide
>
> All this assuming, of course, that everything else is set up correctly.
>
> = Steve =

Thanks very much.
I had forgotten about that. My NetBeans problem was that it didn't have

package Declan;

And that solved it.
Can somebody tell me where to ask about another NetBeans problem? I want to
be able to execute an applet from NetBeans but don't know how. I have a
small html file that means I can run it from IE, but that's a bit of a
nuisance.
Thanks
Allan


Mike Schilling

unread,
Nov 6, 2003, 8:46:38 PM11/6/03
to

"Allan Bruce" <all...@TAKEAWAYf2s.com> wrote in message
news:bodua2$8ke$1...@news.freedom2surf.net...

> And that solved it.
> Can somebody tell me where to ask about another NetBeans problem? I want
to
> be able to execute an applet from NetBeans but don't know how. I have a
> small html file that means I can run it from IE, but that's a bit of a
> nuisance.

Go to www.netbeans.org for information on their mailing lists and
newsgroups.


0 new messages