Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error

 
Lisa Smith
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Lisa Smith
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is a stack trace and how would i use it?
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Lisa Smith
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was the 1st thing I thought of and I stil got the same error. Any other suggestions ?
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Marilyn de Queiroz
Sheriff
Posts: 9064
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic