HunterRS Posted September 11, 2017 Share Posted September 11, 2017 (edited) for some reason I am getting a NullPointerException in this code, I am trying to figure out if I should equip something (after death): for(Item equip: equipmentStart){ if(!getEquipment().contains(equip.getName())){ if(getInventory().contains(equip.getName())){ return State.EQUIP; } } } anyone knows whats wrong with it? EDIT: equipmentStart = getEquipment().getItems(); in onStart() Edited September 11, 2017 by HunterRS Quote Link to comment Share on other sites More sharing options...
Token Posted September 11, 2017 Share Posted September 11, 2017 3 minutes ago, HunterRS said: getEquipment().getItems() Contains null values for empty slots Quote Link to comment Share on other sites More sharing options...
HunterRS Posted September 11, 2017 Author Share Posted September 11, 2017 Just now, Token said: Contains null values for empty slots Ahhh good to know, tyvm Quote Link to comment Share on other sites More sharing options...
whipz Posted September 11, 2017 Share Posted September 11, 2017 4 minutes ago, HunterRS said: for some reason I am getting a NullPointerException in this code, I am trying to figure out if I should equip something (after death): for(Item equip: equipmentStart){ if(!getEquipment().contains(equip.getName())){ if(getInventory().contains(equip.getName())){ return State.EQUIP; } } } anyone knows whats wrong with it? EDIT: equipmentStart = getEquipment().getItems(); in onStart() Do you have it open up the equipment tab on start ? sometimes things cant be grabbed when the interface isnt up. Maybe get it to log the items after equipmentStart in the onStart to make sure its returning an item and not a null 1 Quote Link to comment Share on other sites More sharing options...
Apaec Posted September 11, 2017 Share Posted September 11, 2017 Which line does the NPE Point to? I think it might be the Equipment#contains which is inherited from the ItemContainer class which Equipment extends. In your onStart, it might be worth putting the data into a Map, i.e HashMap<String, EquipmentSlot> initialItems That way you can use Equipment#isWearingItem Apa Quote Link to comment Share on other sites More sharing options...
HunterRS Posted September 11, 2017 Author Share Posted September 11, 2017 Just now, whipz said: Do you have it open up the equipment tab on start ? sometimes things cant be grabbed when the interface isnt up. Maybe get it to log the items after equipmentStart in the onStart to make sure its returning an item and not a null It was because I had null items in my equipmentStart array, didnt know getItems also returns nulls. Just now, Apaec said: Which line does the NPE Point to? I think it might be the Equipment#contains which is inherited from the ItemContainer class which Equipment extends. In your onStart, it might be worth putting the data into a Map, i.e HashMap<String, EquipmentSlot> initialItems That way you can use Equipment#isWearingItem Apa ty, that could be useful, I'll look into that. Quote Link to comment Share on other sites More sharing options...
whipz Posted September 11, 2017 Share Posted September 11, 2017 1 hour ago, HunterRS said: It was because I had null items in my equipmentStart array, didnt know getItems also returns nulls. ty, that could be useful, I'll look into that. ahh sweet glad you figured it out (: Quote Link to comment Share on other sites More sharing options...