Belcampo Posted November 10, 2022 Share Posted November 10, 2022 I'm trying to check if the item's stock is max or higher but it never runs since it always gives the error java.lang.NullPointerException at org.osbot.rs07.api.Store.iIIIIiIIIii(gh:162). String[] BuyItems = {"Name of item", "Name of item", "Name of item"}; int[] Stock = {1, 5, 4}; NPC Shopkeeper = npcs.closest("Shop npc"); Shopkeeper.interact("Trade"); for (int i = 0; i < BuyItems.length; i++) { if (getStore().getAmount(BuyItems[i]) <= Stock[i]) { do something } } I saw some people getting the same problem at the forums but no methods of fixing it except checking if getStore().getAmount(BuyItems[i]) is not null. This didn't work either nor should it work since there is always an amount of that item. Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted November 10, 2022 Share Posted November 10, 2022 Might not be related to your problem but make sure to always null check before using am interact option. NPC Shopkeeper = npcs.closest("Shop npc"); Shopkeeper.interact("Trade"); Should be: NPC Shopkeeper = npcs.closest("Shop npc"); if(shopkeeper != null){ Shopkeeper.interact("Trade"); ... } For the rest, on what line are you getting an NPE? Quote Link to comment Share on other sites More sharing options...
Belcampo Posted November 10, 2022 Author Share Posted November 10, 2022 Interacting with the npc works but I'm getting the error when trying to get the amount of items in stock Quote Link to comment Share on other sites More sharing options...
ExtraBotz Posted November 10, 2022 Share Posted November 10, 2022 I would recommend checking that this isn't returning a null value. getStore().getAmount(BuyItems[i]) Put it in a variable and do a null check on the variable. Your problem may come from the name of the item. It's recommended to use an array of item IDs (you can search the item id here: https://www.osrsbox.com/tools/item-search/) Also, the API is extremely fast. Make sure you're checking that the store is open before running that code. You should only run that loop if getStore.isOpen() returns true. Quote Link to comment Share on other sites More sharing options...
Czar Posted November 10, 2022 Share Posted November 10, 2022 Do if (getStore().contains(BuyItem[i])) { before checking the amount. Also always make sure the array lengths are the same Quote Link to comment Share on other sites More sharing options...
Belcampo Posted November 14, 2022 Author Share Posted November 14, 2022 I thought the script would wait until it opened the store so I didn't check if the store was open. I added the isOpen() and it worked, ty guys! Quote Link to comment Share on other sites More sharing options...