Jump to content

java.lang.NullPointerException


HunterRS

Recommended Posts

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 by HunterRS
Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...