aspose file tools*
The moose likes Beginning Java and the fly likes Total newby question, please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Total newby question, please help" Watch "Total newby question, please help" New topic
Author

Total newby question, please help

simon hargreaves
Greenhorn

Joined: Dec 19, 2002
Posts: 13
Oops, I posted this in the wrong place first time, here goes -
Help,
I am a total newby to Java. Even my first attempts won't work, I am working from a book, according to the book my code should work, but I get the following error.
"Exception in thread "main" java.lang.NoClassDefFoundError:" followed by my filename.
If anyone can help I'd be in yer debt forever, its driving me nuts !
Norm Miller
Ranch Hand

Joined: May 21, 2002
Posts: 56
Simon,
You can get a LOT of help if you show us some code and your classpath.
Monty Ireland
Ranch Hand

Joined: Oct 03, 2000
Posts: 161
So we can help you better.
Please include the following.
1. operations system
2. version of java
3. web browser
4. classpath
5. path
6. java code
7. the name of the book you are using



Multi Platform Database Developer & DBA on E.S.T.
simon hargreaves
Greenhorn

Joined: Dec 19, 2002
Posts: 13
Hi Norm,
Sorry mate, its my first time in here, here's the code :
public class Variables
{
public static void main(String[] args)
{
// Declare and initialise each variable type
char chr = 'M';
String str = "Java 2 in easy steps";
int num = 12345;
// Note float declarations followed by 'f'
float dec = 7f;
boolean flg = false;
// Display the values stored in the variables
System.out.println("Character is " + chr);
}
}
Now to the class path bit, I haven't set one, my book recomends altering autoexec.bat, but I'm running win 2000 server, which has no autoexec.bat, but has autoexec.nt, should I be altering that ? By the way, my helloworld applet worked, so I thought it would all work, my command line to compile is:
C:\java C:\Java_Code\Variables
When I try to compile, there doesn't seem to be a problem, the class file turns up in the directory.
Cheers Simon
simon hargreaves
Greenhorn

Joined: Dec 19, 2002
Posts: 13
Hi Monty,
Good to see your on est, I'm in England so its tea time !
Answers:
OS Win2000 Server
J2EE
Internet explorer (Does this matter for command line stuff ?)
Book - Java 2 in easy steps by Mike McGrath.
Thanks a mill.
Simon
Eric Fletcher
Ranch Hand

Joined: Oct 26, 2000
Posts: 188
Hi Simon,
On Win2K, you don't need to mess with the .bat files to set your classpath, you can just set a CLASSPATH environment variable from the system utility in the control panel. Just set it as you would any other environment variable. Does your book have instructions on where to point the classpath?


My theory of evolution is that Darwin was adopted. - Steven Wright
simon hargreaves
Greenhorn

Joined: Dec 19, 2002
Posts: 13
Hi Eric,
Not at all sure how to do that, I'm in system\advanced\Environment Variables, what next mate ?
Simon
Eric Fletcher
Ranch Hand

Joined: Oct 26, 2000
Posts: 188
Click the "New..." Button from the environment variables dialog, a new dialog will pop up with two text fields:
Variable Name: this should be "CLASSPATH"
Variable Value: this should be the full path to where you installed your SDK jar files and your JRE lib directory. See if your book has instructions on how to set the classpath and set up the path the way they describe. If they don't check out this link: setting the classpath
Give it a try, if you are still having trouble, just post again.
Don't mean to be vague, but it will help you down the road if you check out why you are jumping through all these hoops. Your book or the link should help you with that.
Cheers,
E
simon hargreaves
Greenhorn

Joined: Dec 19, 2002
Posts: 13
Eric,
My book isn't too great on clarity on this,
It tells me to :
SET PATH=C:\WINDOWS;C:WINDOWS\COMMAND;C;\JAVA\BIN;
Well that shoud go into the autoexec.bat file that i don't have, the book also tells me to check that no classpath is set in that file and if so to reset it to SET CLASSPATH=.;
Might as well be writen in Chinese as far as I'm concerned.
Eric Fletcher
Ranch Hand

Joined: Oct 26, 2000
Posts: 188
OK, let's back up a bit here. If you can compile your class and the command prompt doesn't complain about the java command, your PATH is set, so don't worry about that.
Try adding a classpath that looks like this to your environment:
C:\{JDK-PATH}\lib\tools.jar;. <-- this is not a period, it's part of the path
where {JDK-PATH} is the path to your java installation, i.e. Java, or SDK1.4. So if my Java installation is in C:\Java, the path will look like: C:\Java\lib\tools.jar;.
Take a look in the java installation directory, there should be a lib folder and in that folder there should be a file called "tools.jar".
tools.jar is a good file to have in your classpath, and the dot means the current directory is in the classpath as well. You can add additonal directories to the classpath, just separate them with a semi-colon.
Give that a try.
E
[ December 19, 2002: Message edited by: Eric Fletcher ]
[ December 19, 2002: Message edited by: Eric Fletcher ]
simon hargreaves
Greenhorn

Joined: Dec 19, 2002
Posts: 13
Eric,

In my environment variables panel, I have two panes, 'user variables for administrator' & 'System variables', which one should it be in ?
What should I call it, it asks for a variable name and a variable value, I am guessing the path should go in the value field, am I on the right track ? My path looks like being
C:\java\lib\tools
Does that look OK to you ?
Simon
Eric Fletcher
Ranch Hand

Joined: Oct 26, 2000
Posts: 188
Originally posted by simon hargreaves:
In my environment variables panel, I have two panes, 'user variables for administrator' & 'System variables', which one should it be in ?

Probably wouldn't hurt to put it in both. Just duplicate it in both places.
Originally posted by simon hargreaves:
What should I call it, it asks for a variable name and a variable value, I am guessing the path should go in the value field, am I on the right track ?

The variable name should be CLASSPATH, and you are correct, the actual path itself is the value.
Originally posted by simon hargreaves:

C:\java\lib\tools
Does that look OK to you ?

It should look exactly like this:
C:\java\lib\tools.jar;.
For jar files you have to include the ".jar" extension. You may also have to reboot your system for it to take effect.
E
simon hargreaves
Greenhorn

Joined: Dec 19, 2002
Posts: 13
Hi Eric,
Not a sausage mate, no difference at all, still getting the same message
'Exception in thread "main" java.lang.NoClassFoundError: C:\Java_Code\Variables' <<-- Thats my file name
Yet, the class file is there, any other thoughts ?
Eric Fletcher
Ranch Hand

Joined: Oct 26, 2000
Posts: 188
Simon,
I may have missed something pretty simple here

Leave the path off the file, just try
java Variables
May not have seen the forest for the trees here....
Give it a shot.
E
simon hargreaves
Greenhorn

Joined: Dec 19, 2002
Posts: 13
ERIC,
Your a star, apes, ivories and peacocks to your door old mate, it works !!!
Go to the front of the class my boy ! (Hope your English or you might not get that last bit !)
After I put that classpath in, all I needed to do was be in the same directory as the class file and type.
cd Java_Code
C:\Java_Code> prompt appears
C:\Java_Code> java Variables
AND BINGO !!!
Eric Fletcher
Ranch Hand

Joined: Oct 26, 2000
Posts: 188
Glad to help, sorry it took so long, should have spotted it right away.
See, you work with a Development Environment long enough you forget the basics! :roll:
Cheers,
E
simon hargreaves
Greenhorn

Joined: Dec 19, 2002
Posts: 13
Eric,
What environment are you working in as a matter of interest ?
Simon
Eric Fletcher
Ranch Hand

Joined: Oct 26, 2000
Posts: 188
Hi Simon,
I work with JBuilder at home, VisualAge for Java at work.
E
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Total newby question, please help