|
I'm writing a program (yes, homework for intro CS) that plays a quick card game between two computer players and then returns who won (player 1 or 2, it's a random game of luck so theoretically I should be able to run it 1000000 times and see 50/50 winning percentages). I believe my code is correct, and I can run it as many times as I want with no exceptions if I actually run it repeatedly by hand -- but if I insert a for loop to get it to run multiple trials, I invariably end up with an array index out of bounds exception. I'm really confused by this because all of the variables (arrays of cards, stuff like that) are declared either in the for loop or the method called from within the for loop. What kinds of things should I be looking for? What could cause the program to screw up when run multiple times within itself, when I can run it so many times from outside with no incidents, so to speak?
|
# ¿ Mar 10, 2008 06:49 |
|
|
# ¿ May 4, 2024 11:12 |
|
What's the deal with loading images from the web to display in applets? I'm following the directions from this site, but whenever I try to compile, I'm told that the method "getImage()" doesn't exist. I'm doing this within a file that is a smaller class used in the Applet, not the Applet class itself, so could that be the problem? Pretty much the entire program is finished except for this (I was previously working offline as an application, and therefore just using a toolKit) so I'm not willing to move the loading of graphics into the Applet class, unless that's the only way. Ideas? (Just for clarification, here is exactly how I'm trying to implement this: code:
|
# ¿ May 8, 2008 21:02 |
|
ynef posted:You answered your own question, there. Your code attempts to call a method called getImage() in your small class that is used in the Applet class. If you haven't written a method like that, then it is not going to work. Call the Applet class' getImage() method instead. Sorry, I'm still a little confused. Let's say I have two files, MyApplet.java and SmallClass.java. If I want to load an image in SmallClass.java, how do I do it? Moving all of the image related operations that occur in SmallClass to MyApplet is not an option for me right now. There must be some way to load an image in a class that isn't an applet, right? PS - If what you meant was to call Image myImage = MyApplet.getImage("url"); that doesn't seem to work either.
|
# ¿ May 8, 2008 22:50 |
|
Strong Sauce posted:Eh? My problem was with generics. But anyways I figured out that you can't define a constant for the generic type. You want AspectJ. Except no one really wants AspectJ, as far as I can tell. My question, which is less Java related and more "data structures oh god why did I take this class this semester": implementing a splay tree. How strictly is one supposed to follow the rules of splaying every time you access a node? For example, I'm writing a method to return an array representation of the node-keys from an inorder traversal of the tree. Am I supposed to splay after visiting each node ? Or do I only splay after searching expressly for a specific key?
|
# ¿ Nov 30, 2008 19:05 |