Question

I'm doing a card game in swing (java)

The user has to wait his turn, take a card, and press confirm. When it's not his turn, he can't take any card.

It starts this way:

this.cardTaken = false;
board.canTakeCards(!cardTaken);

Then in board class it comes the next action:

public void canTakeCards(boolean can) {
        if (can) {
            this.btnConfirm.setEnabled(false);
            this.pnlCards.setCanTake(true);

        } else {
            this.btnConfirm.setEnabled(true);
            this.pnlCards.setCanTake(false);
        }

(the else happens when the user takes a card).

So. I got the Comparison method violates its general contract at line board.canTakeCards(!cardTaken);

That only happened one time and I "tested" my game for about 8 times. I'm really confused and afraid about this.

One of my theories is that I call this function from 2 differents parts of the code at the same execution time, and it receives a true and false at the same time. But I revised my code and i think that's imposible.

Any advice? Thanks

Was it helpful?

Solution

This message text is included in an exception thrown from Java 7 sorted collections, indicating that the object in question has an inconsistent implementation of compareTo, which basically means it is not imposing a total ordering on the objects. Prior to Java 7 this was silently ignored. Revise your Comparable classes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top