File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes JDK Setup Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JDK Setup Problem" Watch "JDK Setup Problem" New topic
Author

JDK Setup Problem

Luke Thomson
Greenhorn

Joined: Jun 15, 2007
Posts: 6
Hi, I am a complete beginner to Java and I have already got stuck without even looking at a bit of code.

I am having trouble setting up JDK on Windows Vista. I keep getting the following error: Exception in thread "main" java.lang.NoClassDefFoundError

I can compile the code into a source file but get the error message when trying to run the program.

I installed JDK to the default location. I have set the classpath to: .;c:\program files\java\jdk1.6.0_01\lib\tools.jar

The path is set to: c:\program files\java\jdk1.6.0_01\bin

Could anyone tell me what I am doing wrong, I just want to get started.

Thanks in advance,
Luke
John Dell'Oso
Ranch Hand

Joined: Apr 08, 2004
Posts: 130
Luke,

From which directory are you trying to run your program? Is it from the directory where your class files resides? Perhaps you can post your code just to make sure there isn't a problem there.

Regards,
JD
Luke Thomson
Greenhorn

Joined: Jun 15, 2007
Posts: 6
The directory that I am trying to run from is a seperate folder on the drive, I change to this directory at the command line. Compile the code then try running it.

Even a simple hello world doesn't seem to work, but if I try running this:


I get the same error but with a list of other errors like:
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineclass(Unknown Source)

Hope this is helps
John Dell'Oso
Ranch Hand

Joined: Apr 08, 2004
Posts: 130
Luke,

Can you post all of the code. Do you have a package statement at the beginning of your code?

Regards,
JD
Luke Thomson
Greenhorn

Joined: Jun 15, 2007
Posts: 6
That is all the code that I am using to test the install.

I appreciate you help,
Luke
John Dell'Oso
Ranch Hand

Joined: Apr 08, 2004
Posts: 130
Luke,

I apologise if this sounds like a silly question, but are you sure that the source compiled successfully? Do you have a HelloUser.class file in your directory?

Try running the program like so:

java -cp . HelloUser

Regards,
JD
Luke Thomson
Greenhorn

Joined: Jun 15, 2007
Posts: 6
Hi again John,

Using java -cp . HelloUser works.

How could I get it to work without using -cp? Do I need to change the classpath, I thought that a classpath starting with .; makes it look for the class file in the current directory.

Anyway, thanks for getting me started and for your quick replies,
Luke
John Dell'Oso
Ranch Hand

Joined: Apr 08, 2004
Posts: 130
Luke,

Glad to hear that we got something working.

At the command prompt type the following command and let me know what the result is.

echo %classpath%

Regards,
JD
Luke Thomson
Greenhorn

Joined: Jun 15, 2007
Posts: 6
echo %classpath% gives me .;c:\program files\java\jdk1.6.0_01\lib\tools.jar
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Weird. The current directory (dot) appears to be in the classpath, and yet it won't work unless you run with a classpath flag specifying the current directory...?

Wild guess: Does your classpath include a space before the period? If so, you should remove the space.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14433
    
  23

Why are you including c:\program files\java\jdk1.6.0_01\lib\tools.jar in your classpath? That's not necessary.

In fact, it is not necessary at all to set the classpath environment variable. If you leave it unset, Java will by default look in the current directory for class files.

So my advice is: just delete your classpath environment variable (leave it unset).


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
Originally posted by Luke Thomson:
... I thought that a classpath starting with .; makes it look for the class file in the current directory....

It does.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Any progress on this? (A space in the system classpath, perhaps?) I'm curious what this issue is.
Michael W Wright
Greenhorn

Joined: Sep 13, 2007
Posts: 1
I had the same problem with JDK on Vista 64. Short story is I've got XP at work where I've been working on the 'Headfirst into Java' book. I brought it home, set it up on Vista and continued on.

I typed in the example for the SimpleGui1

It compiled fine.
When I went to run it, I got:
Exception in thread "main" java.lang.NoClassDefFoundError: SimpleGui1

I searched here, found this discussion and checked my classpath which showed up as:
.;C:\Program Files (x86)\QuickTime\QTSystem\QTJava.zip

I deleted the classpath variable and it started working.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14433
    
  23

Originally posted by Michael W Wright:
I searched here, found this discussion and checked my classpath which showed up as:
.;C:\Program Files (x86)\QuickTime\QTSystem\QTJava.zip

That's because you have installed Apple QuickTime on your computer. It has the nasty habit of changing your classpath... :roll:
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19785
    
  20

Here's a hint:
Put the pieces of the path with spaces in them between quotes.

You'd get .;"C:\Program Files (x86)\QuickTime\QTSystem\QTJava.zip"

File systems have some problems when you pass paths / files with spaces but not surround them with quotes. For instance, they stop at C:\Program, and ignore the rest.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Marc Morin
Greenhorn

Joined: Sep 18, 2007
Posts: 1
Hi,

I am beginner in Java to and when I try to run this code:



with that command line � C:\>java HelloUser �
I had this error: � Exception in thread "main" java.lang.NoClassDefFoundError: HelloUser �

Obviously I did not compiled my file HelloUser.java with the command � C:\>javac HelloUser.java �

Now that I have it compiled it's working.

Hope this is helps
MM
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Marc Morin:
...Now that I have it compiled it's working...

Welcome to JavaRanch! I'm glad you got this figured out.

Michael Raymond Jr.
Ranch Hand

Joined: May 16, 2005
Posts: 178
Originally posted by Luke Thomson:
Hi, I am a complete beginner to Java and I have already got stuck without even looking at a bit of code.

I am having trouble setting up JDK on Windows Vista. I keep getting the following error: Exception in thread "main" java.lang.NoClassDefFoundError

I can compile the code into a source file but get the error message when trying to run the program.

I installed JDK to the default location. I have set the classpath to: .;c:\program files\java\jdk1.6.0_01\lib\tools.jar

The path is set to: c:\program files\java\jdk1.6.0_01\bin

Could anyone tell me what I am doing wrong, I just want to get started.

Thanks in advance,
Luke



try removing that c:\program files\java\jdk1.6.0_01\lib\tools.jar and see if that works. remember, you have to close the shell and reopen a new after schanging the system variables if not doen from the command line.


Scooby Snacks for everyone...<br /> <br />SCJA, SCJP 1.4
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDK Setup Problem