This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error" Watch "Error" New topic
Author

Error

Lisa Smith
Ranch Hand

Joined: Sep 24, 2002
Posts: 57
Exception in thread "main" java.lang.NoSuchMethodError: main
I cannot figure out wht this is not working.
Above is the error below is the code. It compiles but I get this error
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Lisa try posting the full stack trace. My first instinct on this is that the JVM is trying to use an older version of some class, but it's hard to say without the trace.


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Lisa Smith
Ranch Hand

Joined: Sep 24, 2002
Posts: 57
what is a stack trace and how would i use it?
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Originally posted by Lisa Smith:
what is a stack trace and how would i use it?

Show the whole list of Exceptions generated. It should look something like this:

Lisa Smith
Ranch Hand

Joined: Sep 24, 2002
Posts: 57
I don't get it. Should I write this code within the class and where or is used at the command line?
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Originally posted by Lisa Smith:
I don't get it. Should I write this code within the class and where or is used at the command line?

I went back and read your first post again. Looks like I was a bit confused. The problem is you don't have a main method in that code. To start a java application you must have a method with the following signature:

Did you write this code?
Gaurav Mac Mathur
Ranch Hand

Joined: Feb 19, 2002
Posts: 47
Well Michael,
this certainly is not a stand alone program...
as we will be needing other objects also (Deck, BlackjackHand and Card ) to compile this code...
we need more details of about what is this all about
cheers Gaurav
Lisa Smith
Ranch Hand

Joined: Sep 24, 2002
Posts: 57
THIS IS DECK
public class BlackjackHand extends Hand {

public int getBlackjackValue() {
// Returns the value of this hand for the
// game of Blackjack.
int val; // The value computed for the hand.
boolean ace; // This will be set to true if the
// hand contains an ace.
int cards; // Number of cards in the hand.
val = 0;
ace = false;
cards = getCardCount();
for ( int i = 0; i < cards; i++ ) {
// Add the value of the i-th card in the hand.
Card card; // The i-th card;
int cardVal; // The blackjack value of the i-th card.
card = getCard(i);
cardVal = card.getValue(); // The normal value, 1 to 13.
if (cardVal > 10) {
cardVal = 10; // For a Jack, Queen, or King.
}
if (cardVal == 1) {
ace = true; // There is at least one ace.
}
val = val + cardVal;
}
// Now, val is the value of the hand, counting any ace as 1.
// If there is an ace, and if changing its value from 1 to
// 11 would leave the score less than or equal to 21,
// then do so by adding the extra 10 points to val.
if ( ace == true && val + 10 <= 21 )
val = val + 10;
return val;
} // end getBlackjackValue()

} // end class BlackjackHand
also card

Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
The problem is exactly as stated previously: you don't have a main() method. It looks like program() is meant to be your entry point. You should change the line

to

HTH
Layne
p.s. The whole thing about the stack trace is that Michael Morris wanted to see the complete output you get when running the program. He was simply asking you to copy and paste it here, not change your code in any way. However, the above explanation should help you fix the problem.


Java API Documentation
The Java Tutorial
Lisa Smith
Ranch Hand

Joined: Sep 24, 2002
Posts: 57
That was the 1st thing I thought of and I stil got the same error. Any other suggestions ?
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
static public void main(String[] args) is what Layne meant to type, try that.
In the main method you will want to create some instances (objects) of some of these classes and call the appropriate methods to activate a new game.
[ July 12, 2003: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
Hi Lisa.
You have four classes, BlackjackConsole, Deck, Hand, and BLackjackhand. To run the program you type
java BlackjackConsole

Am I right so far?

So the JVM goes to the BlackjackConsole class and looks for a method with the signature of
public static void main( String[] args )

If it doesn't find it, the JVM prints an error message to your screen -- something like

Exception in thread "main" java.lang.NoSuchMethodError: main

This message (all of it) is the "stack trace".

Now it seems that you used to have a method named main because at the end of the program() method you have a comment "// end main". I suggest that you change the name of the method back to

and try to run the program again.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error
 
Similar Threads
Blackjack program not good with random cards
Need help with Blackjack game
can't split card shuffle method into a separate class
no such method error
Synchronize the way threads(players) take their turn.