Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Help with my Java applet

 
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.
 
Rancher
Posts: 43016
76
  • 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: 43016
76
  • 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.
 
Space pants. Tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic