i'm making an app that makes an API request and gets back a list of Games, with one of the fields being the release date in seconds Timestamp.
When i make the call for e.g. call of duty the sorting goes well, but if i do so for like zelda it throws java.lang.IllegalArgumentException: Comparison method violates its general contract!
I filter out the ones that return a null release date, but I don't know why with some games it just don't work.
Here is the code for the sorting
Collections.sort(mGames, new Comparator<Game>() {
@Override
public int compare(Game o1, Game o2) {
if(o1.getDate() != null && o2.getDate() != null)
return Integer.valueOf(o2.getDate()).compareTo(Integer.valueOf(o1.getDate()));
return 1;
}
});
and the responses (some of them) for spyro search (which works)
2020-06-04 01:07:22.723 26928-26928/it.unimib.disco.gruppoade.gamenow D/SearchActivity: onResponse: Release date = 941500800 Name = Spyro 2: Ripto's Rage!
2020-06-04 01:07:22.723 26928-26928/it.unimib.disco.gruppoade.gamenow D/SearchActivity: onResponse: Release date = 1542067200 Name = Spyro Reignited Trilogy
2020-06-04 01:07:22.723 26928-26928/it.unimib.disco.gruppoade.gamenow D/SearchActivity: onResponse: Release date = 1086220800 Name = Spyro Orange: The Cortex Conspiracy
2020-06-04 01:07:22.723 26928-26928/it.unimib.disco.gruppoade.gamenow D/SearchActivity: onResponse: Release date = 1004313600 Name = Spyro: Season of Ice
2020-06-04 01:07:22.723 26928-26928/it.unimib.disco.gruppoade.gamenow D/SearchActivity: onResponse: Release date = 972432000 Name = Spyro: Year of the Dragon
2020-06-04 01:07:22.723 26928-26928/it.unimib.disco.gruppoade.gamenow D/SearchActivity: onResponse: Release date = 1067212800 Name = Spyro: Attack of the Rhynocs
2020-06-04 01:07:22.723 26928-26928/it.unimib.disco.gruppoade.gamenow D/SearchActivity: onResponse: Release date = 1191283200 Name = The Legend of Spyro: The Eternal Night
2020-06-04 01:07:22.723 26928-26928/it.unimib.disco.gruppoade.gamenow D/SearchActivity: onResponse: Release date = 1542067200 Name = Spyro + Crash Remastered Game Bundle
2020-06-04 01:07:22.724 26928-26928/it.unimib.disco.gruppoade.gamenow D/SearchActivity: onResponse: Release date = null Name = Spyro Fusion
2020-06-04 01:07:22.724 26928-26928/it.unimib.disco.gruppoade.gamenow D/SearchActivity: onResponse: Release date = null Name = Spyro Superpack
and for e.g. pokemon, just some, (which crashes and caused the java.lang.IllegalArgumentException: Comparison method violates its general contract!
2020-06-04 01:08:24.100 26928-26928/it.unimib.disco.gruppoade.gamenow D/SearchActivity: onResponse: Release date = 1573776000 Name = Pokémon Sword & Pokémon Shield Double Pack
2020-06-04 01:08:24.100 26928-26928/it.unimib.disco.gruppoade.gamenow D/SearchActivity: onResponse: Release date = 1129766400 Name = Pokémon Trozei!
2020-06-04 01:08:24.100 26928-26928/it.unimib.disco.gruppoade.gamenow D/SearchActivity: onResponse: Release date = 1366761600 Name = Pokémon Rumble U
2020-06-04 01:08:24.100 26928-26928/it.unimib.disco.gruppoade.gamenow D/SearchActivity: onResponse: Release date = 1141603200 Name = Pokemon Link!
2020-06-04 01:08:24.100 26928-26928/it.unimib.disco.gruppoade.gamenow D/SearchActivity: onResponse: Release date = 913939200 Name = Pokémon Trading Card Game
2020-06-04 01:08:24.100 26928-26928/it.unimib.disco.gruppoade.gamenow D/SearchActivity: onResponse: Release date = null Name = Pokemon-e: Expedition
2020-06-04 01:08:24.100 26928-26928/it.unimib.disco.gruppoade.gamenow D/SearchActivity: onResponse: Release date = 1413849600 Name = Camp Pokémon
2020-06-04 01:08:24.100 26928-26928/it.unimib.disco.gruppoade.gamenow D/SearchActivity: onResponse: Release date = 943142400 Name = Pokémon Gold
2020-06-04 01:08:24.100 26928-26928/it.unimib.disco.gruppoade.gamenow D/SearchActivity: onResponse: Release date = 924048000 Name = Pokémon Pinball
2020-06-04 01:08:24.100 26928-26928/it.unimib.disco.gruppoade.gamenow D/SearchActivity: onResponse: Release date = 1075334400 Name = Pokémon FireRed
2020-06-04 01:08:24.100 26928-26928/it.unimib.disco.gruppoade.gamenow D/SearchActivity: onResponse: Release date = 925430400 Name = Pokémon Stadium
as you can see they both have some that contain the date and some null. But spyro works and pokemon doesn't and I can't understand why.
Thank you