Java Main
Toasted here again, ive got to admit im annoyed. I searched my heart out on the net to find a solution to this problem but couldn''t find anything. Having converted my hangman from an applet in Java to a stand alone app I get the following error java.lang.NoClassDefFoundError
Yes I do have the following main procedure:
public static void main(String args[])
{
hangman demo = new hangman();
demo.setSize(500,400);
demo.makeGui();
demo.setVisible(true);
}
This is probably a trivial problem for most people, so trivial in fact that noone on the net bothered offering a solution for it probably....
Cheers
The most common cause here is you have named the file differently to the class name.
Java treats class name and file names in a case sensitive manner, so if you have:
public class Hangman{.....}
You need to save it in a file called Hangman.java NOT hangman.java
And obviously your constructor needs to be: public Hangman(){..} as well.
If this doesn''t work I have a few other ideas, but let me know if that fixes it first.
MrChris
Java treats class name and file names in a case sensitive manner, so if you have:
public class Hangman{.....}
You need to save it in a file called Hangman.java NOT hangman.java
And obviously your constructor needs to be: public Hangman(){..} as well.
If this doesn''t work I have a few other ideas, but let me know if that fixes it first.
MrChris
Is your class called *exactly* the same thing as the file? ie, if your class is called "hangman" your file should be called "hangman.java".
Actually, is the error occuring when you try and run the program? If so, check you are running it properly. You should be typing "javac hangman". Note you do not need to put any extension on the file (ie, dont type "javac hangman.class", and definatly dont type "javac hangman.java").
Alan
-----
"A thousand years ago man thought the moon was made of cheese;
Thirty years ago we went to the moon and found it was made of rock;
We have not been back since;
See the power of cheese?"
Actually, is the error occuring when you try and run the program? If so, check you are running it properly. You should be typing "javac hangman". Note you do not need to put any extension on the file (ie, dont type "javac hangman.class", and definatly dont type "javac hangman.java").
Alan
-----
"A thousand years ago man thought the moon was made of cheese;
Thirty years ago we went to the moon and found it was made of rock;
We have not been back since;
See the power of cheese?"
"There will come a time when you believe everything is finished. That will be the beginning." -Louis L'Amour
quote: Original post by AlanKemp
definatly dont type "javac hangman.java").
Eh?!? That''s wrong, if anything you SHOULD be typing ''javac hangman.java''. I think what you meant was don''t type ''java hangman.java''. For simplicities sake when building small projects where there are very few interdependacies and you aren''t using packaged code you can compile with a simple ''javac *.java'' command.
I''ll assume that was a typo and you aren''t mad
MrChris
> I''ll assume that was a typo and you aren''t mad
Arrghh :-)
It was a typo. I apologise, I should be more carefull when offering advice to others not to make silly mistakes myself.
Alan
Arrghh :-)
It was a typo. I apologise, I should be more carefull when offering advice to others not to make silly mistakes myself.
Alan
"There will come a time when you believe everything is finished. That will be the beginning." -Louis L'Amour
I feel a bit of a dufus actually.
About 2 hours after I wrote the post I found the extremly simple solution:
- javac hangman.java to compile it
- java hangman
I was typing java hangman.java for the second bit :-(
About 2 hours after I wrote the post I found the extremly simple solution:
- javac hangman.java to compile it
- java hangman
I was typing java hangman.java for the second bit :-(
I feel a bit of a dufus actually.
About 2 hours after I wrote the post I found the extremly simple solution:
- javac hangman.java to compile it
- java hangman
I was typing java hangman.java for the second bit :-(
working on getting a random word from the file now, should be fun
About 2 hours after I wrote the post I found the extremly simple solution:
- javac hangman.java to compile it
- java hangman
I was typing java hangman.java for the second bit :-(
working on getting a random word from the file now, should be fun
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement