InsufficientLevelException at LevelUp
Description: When reaching the next level, a InsufficientLevelException is thrown.
Stacktrace (If it's a crash): Exception in thread "Async HTTP Thread" com.pokegoapi.exceptions.InsufficientLevelException at com.pokegoapi.api.player.PlayerProfile.acceptLevelUpRewards(PlayerProfile.java:217) at com.pokegoapi.api.player.PlayerProfile.setStats(PlayerProfile.java:386) at com.pokegoapi.api.inventory.Inventories.updateInventories(Inventories.java:179) at com.pokegoapi.main.CommonRequests.handleCommons(CommonRequests.java:135) at com.pokegoapi.main.RequestHandler.run(RequestHandler.java:419) at java.lang.Thread.run(Unknown Source)
Cause: Logical bug
PlayerProfile.acceptLevelUpRewards is called in PlayerProfile.setStats before PlayerProfile.stats are updated This causes the method to throw the exception because newLevel is always greater than stats.getLevel().
public void setStats(Stats stats) throws RequestFailedException {
final int newLevel = stats.getLevel();
if (this.stats != null) {
if (newLevel > this.level) {
List<PlayerListener> listeners = api.getListeners(PlayerListener.class);
for (PlayerListener listener : listeners) {
listener.onLevelUp(api, level, newLevel);
}
acceptLevelUpRewards(newLevel);
}
}
this.stats = stats;
this.level = newLevel;
}
public PlayerLevelUpRewards acceptLevelUpRewards(int level)
throws RequestFailedException {
// Check if we even have achieved this level yet
if (level > stats.getLevel()) {
throw new InsufficientLevelException();
}
I've been testing hrk's fix, it appears to suppress the InsufficientLevelException, however, the API will hang if you level up by catching a Pokemon. It's difficult to pinpoint because no Exception is thrown but if you throw a ball and catch a Pokemon which triggers a level up, then I think encounter.status() get stuck resolving and the program just hangs. Can anyone verify they are getting the same issue?
Yes. I get the same issue when i tried to fix the InsufficientLevelException myself. Interestingly, there is a AcceptLevelUpReward message at login and this works. Currently I'm catching the InsufficientLevelException in the onLevelUp method of the PlayerListener and exit my bot. With the next login I'm getting the reward.
wrong button ;-)
extract from my logfile: after new login the itembag contains the rewarded items.
new Level reached. old:30, new:31 com.pokegoapi.exceptions.InsufficientLevelException +++++++++++++++++++++++++++++++ Itembag...... +++++++++++++++++++++++++++++++ Item: ITEM_POKE_BALL, Count: 1 Item: ITEM_GREAT_BALL, Count: 103 Item: ITEM_ULTRA_BALL, Count: 105 Item: ITEM_SUPER_POTION, Count: 13 Item: ITEM_HYPER_POTION, Count: 13 Item: ITEM_MAX_POTION, Count: 64 Item: ITEM_REVIVE, Count: 58 Item: ITEM_MAX_REVIVE, Count: 26 Item: ITEM_LUCKY_EGG, Count: 51 Item: ITEM_INCENSE_ORDINARY, Count: 12 Item: ITEM_TROY_DISK, Count: 9 Item: ITEM_RAZZ_BERRY, Count: 5 Item: ITEM_PINAP_BERRY, Count: 4 Item: ITEM_INCUBATOR_BASIC_UNLIMITED, Count: 1 Item: ITEM_INCUBATOR_BASIC, Count: 7 Item: ITEM_SUN_STONE, Count: 6 Item: ITEM_KINGS_ROCK, Count: 2 Item: ITEM_METAL_COAT, Count: 1 Item: ITEM_DRAGON_SCALE, Count: 4 Item: ITEM_UP_GRADE, Count: 3 +++++++++++++++++++++++++++++++ exit.....
20-04-2017 09:28:16 Successfully logged in ! +++++++++++++++++++++++++++++++ Load Player data.... +++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++ Player Stats.... +++++++++++++++++++++++++++++++ Name xxxxxxxxxxxxx Level: 31 Next Level at: 3000000 Progress: 501989/1000000 Expirience: 2501989 Items 538/500 Pokemons 267/350 To Evolve: 63 Encountered/Catched: 5960/5263 283,704 Km walked Attack Battels won: 67/67 Trainings won: 126/126 STARDUST: 384114 POKECOIN: 40 Daily Defender Bonus available at: 21-04-2017 03:36:13 +++++++++++++++++++++++++++++++ Itembag...... +++++++++++++++++++++++++++++++ Item: ITEM_POKE_BALL, Count: 1 Item: ITEM_GREAT_BALL, Count: 103 Item: ITEM_ULTRA_BALL, Count: 115.........................+10 Item: ITEM_SUPER_POTION, Count: 13 Item: ITEM_HYPER_POTION, Count: 13 Item: ITEM_MAX_POTION, Count: 79..........................+15 Item: ITEM_REVIVE, Count: 58 Item: ITEM_MAX_REVIVE, Count: 36..........................+10 Item: ITEM_LUCKY_EGG, Count: 51 Item: ITEM_INCENSE_ORDINARY, Count: 12 Item: ITEM_TROY_DISK, Count: 9 Item: ITEM_RAZZ_BERRY, Count: 5 Item: ITEM_NANAB_BERRY, Count: 15..........................+15 Item: ITEM_PINAP_BERRY, Count: 4 Item: ITEM_INCUBATOR_BASIC_UNLIMITED, Count: 1 Item: ITEM_INCUBATOR_BASIC, Count: 7 Item: ITEM_SUN_STONE, Count: 6 Item: ITEM_KINGS_ROCK, Count: 2 Item: ITEM_METAL_COAT, Count: 1 Item: ITEM_DRAGON_SCALE, Count: 4 Item: ITEM_UP_GRADE, Count: 3
That's a good idea, listen for level up trigger and just log in and out. Not a great solution but at least it no longer freezes up. Thanks!