• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with my Java applet

 
Alex Desjardins
Greenhorn
Posts: 10
Eclipse IDE MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I have two questions.

1 - I don't understand why I'm getting an empty stack error when calling the removecard method in my Table class line 13?

2 - I am trying to use a constructor to populate my deck of cards instead of a method when creating my theDeck object in my Table class line 11 but I get the following error:

java.lang.StackOverflowError
at java.util.Vector.<init>(Unknown Source)
at java.util.Vector.<init>(Unknown Source)
at java.util.Stack.<init>(Unknown Source)
at Deck.<init>(Deck.java:7)
at Deck.<init>(Deck.java:34)







Thank you for your time.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A couple things you may want to start with:

Never compare strings with the "==" operator, always use the "equals" method.

Deck.buildDeck allocates a Deck object - it should not. A Deck object has already been allocated in the Table class. Instead of calling the various "deck.XYZ()" methods, buildDeck should call "XYZ()" directly.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, I'm not getting the error you observed, just an "Error, empty stack" because of the problem in the Deck class I mentioned. If I fix that, everything looks normal (well, as expected, anyway :-) ).

As long as you don't have a GUI inplace, you may want to redefine you Table class like this so you can run it from the command line without the applet stuff:

 
Alex Desjardins
Greenhorn
Posts: 10
Eclipse IDE MySQL Database PHP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, thank you Ulf Dittmer, now I understand! I still have to go over everything but that makes sense. Again thank you for your help ; ) And I will fix the equal thing when comparing strings.

Edit:

And the constructor is working now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic