Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Java woes when running anything

Reply
Thread Tools

Java woes when running anything

 
 
Allan Bruce
Guest
Posts: n/a
 
      11-06-2003
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(Secure ClassLoader.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.j ava:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 89)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 35)
at java.lang.ClassLoader.loadClassInternal(ClassLoade r.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


 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      11-06-2003
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
 
Reply With Quote
 
 
 
 
Allan Bruce
Guest
Posts: n/a
 
      11-06-2003
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" <> wrote in message
news:...
> 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



 
Reply With Quote
 
Steve W. Jackson
Guest
Posts: n/a
 
      11-06-2003
In article <bodo8i$6q8$>,
"Allan Bruce" <> wrote:

>: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(Secu reClassLoader.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.j ava:187)
>: at java.lang.ClassLoader.loadClass(ClassLoader.java:2 89)
>: at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:274)
>: at java.lang.ClassLoader.loadClass(ClassLoader.java:2 35)
>: at java.lang.ClassLoader.loadClassInternal(ClassLoade r.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.
>erhaps 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


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
 
Reply With Quote
 
Allan Bruce
Guest
Posts: n/a
 
      11-06-2003
> 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


 
Reply With Quote
 
Mike Schilling
Guest
Posts: n/a
 
      11-07-2003

"Allan Bruce" <> wrote in message
news:bodua2$8ke$...
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i get firewire (ieee 1394) running on virtual anything? charles kuchar Windows 64bit 3 01-29-2010 12:54 AM
Code doesn't produce anything on screen - Doesn't give any erroreither while compiling / running. Vasu Java 2 10-18-2008 04:36 AM
Firefox / Java applet woes under ubuntu. Pacific Dragon NZ Computing 1 01-11-2006 09:35 PM
Java newbie: RMI woes on Linux Andy Java 4 11-11-2004 09:37 AM
java woes (win98se) and mozilla Tendril Firefox 1 10-19-2003 04:04 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57