Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDK Setup Problem

 
Luke Thomson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is all the code that I am using to test the install.

I appreciate you help,
Luke
 
John Dell'Oso
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
echo %classpath% gives me .;c:\program files\java\jdk1.6.0_01\lib\tools.jar
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15436
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any progress on this? (A space in the system classpath, perhaps?) I'm curious what this issue is.
 
Michael W Wright
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15436
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20605
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marc Morin
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic