This site requires JavaScript, please enable it in your browser!
Greenfoot back
kiarocks
kiarocks wrote ...

2012/1/2

New problem.

1
2
kiarocks kiarocks

2012/1/2

#
Why does this give
java.lang.ArrayIndexOutOfBoundsException: 535
	at Pad.act(Pad.java:56)
	at greenfoot.core.Simulation.actActor(Simulation.java:507)
	at greenfoot.core.Simulation.runOneLoop(Simulation.java:470)
	at greenfoot.core.Simulation.runContent(Simulation.java:204)
	at greenfoot.core.Simulation.run(Simulation.java:194)
//Code
System.out.println("Unknown failure");
                failtimes[value]++;//line 56
                System.out.println("Fail times: "+failtimes[value]+" Pad number "+value);
//Note: failtimes has an index of Integer.MAX_VALUE, so it is like impossible to go out of bounds.
danpost danpost

2012/1/2

#
Are you saying that 'value == Integer.MAX_VALUE' is true? or is value actually 535 (like it is telling you)? Without related context, it is unclear. Anyway, in card class 'checkClick(boolean)' within the 'if(location)'s, add the line 'sw.deck.lastCardGiven--;'. That should correct the deck issue. Oh, I did say 'sw.deck' instead of 'Deck' (I eliminated 'static' and changed all 'Deck' to 'sw.deck'). Did that so resetting would not present errors due to incorrect values.
kiarocks kiarocks

2012/1/2

#
value is 535, the declaration is
int[] failtimes = new int[Integer.MAX_VALUE];
I already fixed the deck issue.
danpost danpost

2012/1/2

#
Are you back on track, now? Back to building, or still fixin'??
kiarocks kiarocks

2012/1/2

#
like a fix on this, it still is not working.
mjrb4 mjrb4

2012/1/2

#
It's difficult to say with the code you posted - but if you're getting that error, and line 56 is the one you say it is, then failtimes must have a size of 535 or less, not Integer.MAX_VALUE. We'll need to see more code to work out exactly where the problem is.
danpost danpost

2012/1/2

#
What problems are you still having? My last post, you know, was to correct the problem of the deck skipping a card after one was taken from it (which was causing it to look like the deck stopped working after reaching the end -- but not actually appearing like it was at the end). It looked like there was another card to flip, but would not flip it, where in fact, all cards had been flipped and the deck did not signify it.
kiarocks kiarocks

2012/1/3

#
a lot of things have been changed, i will add that.
kiarocks kiarocks

2012/1/3

#
Oh, it turns out since even though 2^31-1 is Integer.MAX_VALUE, it is not the same and now it works with a size of 1000. But there is a new problem. this
for(int i = 0; i < cards.size(); i++)
        {
            Card card = (Card) getOneObjectAtOffset(0,i*20,Card.class);
            if(card != null && card.sideShown)
            {
                shown[i] = i;
                spot++;
            }
            else shown[i] = -1;
        }
        int lasPos = 0;
        int[] failtimes = new int[1000];  

        for(int i = 0;i <= spot; i++)
        {
            Card card = null;
            try
            {
                if(shown[i] != -1) card = (Card) getOneObjectAtOffset(0,shown[i]*20,Card.class);
            }
            catch(ArrayIndexOutOfBoundsException arrayex)
            {
                System.out.println("Unknown failure");
                failtimes[value]++;
                System.out.println("Fail times: "+failtimes[value]+" Pad number "+value);
            }
            if(card != null)
            {
                card.posonstack = lasPos+1;
                lasPos++;
                card.cardsinstack = spot;
                card.dragStack = true;
                if(i == spot) card.dragStack = false;
                if(i > 0) card.onStack = true;
                if(i == 0) stackLead = card;
                card.ignoreMouse = true;
                dragStack.add(card);
            }
        }
prints out
Fail times: 216 Pad number 535
Unknown failure
Fail times: 217 Pad number 535
Unknown failure
Fail times: 218 Pad number 535
Unknown failure
Fail times: 219 Pad number 535
Unknown failure
Fail times: 220 Pad number 535
Unknown failure
Fail times: 221 Pad number 535
Unknown failure
Fail times: 222 Pad number 535
Unknown failure
Fail times: 223 Pad number 535
Unknown failure
Fail times: 224 Pad number 535
Unknown failure
Fail times: 225 Pad number 535
Unknown failure
Fail times: 226 Pad number 535
Unknown failure
Fail times: 227 Pad number 535
Unknown failure
Fail times: 228 Pad number 535
Unknown failure
Fail times: 229 Pad number 535
Unknown failure
Fail times: 230 Pad number 535
Unknown failure
Fail times: 231 Pad number 535
Unknown failure
Fail times: 232 Pad number 535
Unknown failure
Fail times: 233 Pad number 535
Unknown failure
Fail times: 234 Pad number 535
Unknown failure
Fail times: 235 Pad number 535
Unknown failure
Fail times: 236 Pad number 535
Unknown failure
Fail times: 237 Pad number 535
Unknown failure
Fail times: 238 Pad number 535
Unknown failure
Fail times: 239 Pad number 535
etc.,ect.,ect.
kiarocks kiarocks

2012/1/3

#
A recompile results in this instead
Fail times: 219 Pad number 615
Unknown failure
Fail times: 220 Pad number 615
Unknown failure
Fail times: 221 Pad number 615
Unknown failure
Fail times: 222 Pad number 615
Unknown failure
Fail times: 223 Pad number 615
Unknown failure
Fail times: 224 Pad number 615
Unknown failure
Fail times: 225 Pad number 615
Unknown failure
Fail times: 226 Pad number 615
Unknown failure
Fail times: 227 Pad number 615
Unknown failure
Fail times: 228 Pad number 615
Unknown failure
Fail times: 229 Pad number 615
Unknown failure
Fail times: 230 Pad number 615
Unknown failure
Fail times: 231 Pad number 615
Unknown failure
Fail times: 232 Pad number 615
Unknown failure
Fail times: 233 Pad number 615
Unknown failure
Fail times: 234 Pad number 615
Unknown failure
Fail times: 235 Pad number 615
Unknown failure
Fail times: 236 Pad number 615
Unknown failure
Fail times: 237 Pad number 615
Unknown failure
Fail times: 238 Pad number 615
Unknown failure
Fail times: 239 Pad number 615
Unknown failure
Fail times: 240 Pad number 615
Unknown failure
Fail times: 241 Pad number 615
Unknown failure
Fail times: 242 Pad number 615
danpost danpost

2012/1/3

#
'spot' appears to be a counting number (starting at 0 for none to n for whatever). If your 'for' loop at line 14 is supposed to run through 'spot' times, you need to make the qualifier 'i < spot;' (not 'i <= spot';).
kiarocks kiarocks

2012/1/3

#
that is not important, i found the problem: spot increments(this is in the act method) and just keeps going until it reaches Integer.MAX_VALUE.
danpost danpost

2012/1/3

#
All right!! <<(figure of speech) What is next?
kiarocks kiarocks

2012/1/3

#
Nothing, working on dragging piles. How did you do it?
danpost danpost

2012/1/3

#
I created an object to carry the run of cards (sort of like an invisible hand). It would be created with a list of cards going to its constructor, which was the only info it held. Its only function was to follow the mouse and bring the cards along with it. I had made Pad a super-class of the draw, foundation, and tableau piles. Each pad has a String value saying what kind of pad it is, which aided in determining whose method to call for adding and removing cards. Also, as soon as the object that transfers the cards get them, they are removed from the givers list. If the move was unsuccessful, I made the 'from Pad' the 'to Pad' so they would be added right back where they came from. One of the few card variables is a reference to which pad it is on, so finding where they came from was easy (I had the reference to the card in the transfer object; the card(s) had a reference to the pad it/they came from; the pad reference in the card told me what kind of pad it was). As soon as the cards were added back to a pad, the transfer object is removed.
There are more replies on the next page.
1
2