• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Total newby question, please help

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simon,
You can get a LOT of help if you show us some code and your classpath.
 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
simon hargreaves
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
simon hargreaves
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Eric,
What environment are you working in as a matter of interest ?
Simon
 
Eric Fletcher
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Simon,
I work with JBuilder at home, VisualAge for Java at work.
E
 
Not looking good. I think this might be the end. Wait! Is that a tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic