Jump to content

getItems(); throws NullPointerException


senpai jinkusu

Recommended Posts

It would have worked even if it was an interface.

But yeah, any method defined in the superclass can be invoked on the subclass instances, even if the static type is the superclass.

 

you know im glad you mentioned the getInventory function, whenever i use just "inventory" it will return the correct number of ores on the first cycle then the next 3 it returns 0, either way here is the final code minus the removal of generics

<T extends ItemContainer>int getOreCount ( T itemContainer, int... IDs)

{
	if (itemContainer != null)
	 return (int)itemContainer.getAmount(IDs);
	return 0;

}
 public int onLoop() throws InterruptedException

{

  log(Integer.toString(getOreCount(getInventory(),IDs[0],IDs[1])));
return random(200, 300);
}
 

which so far is working fine and ended up being way more efficient than the old code, although Im not sure if checking for a null ItemContainer reference is necessary since that never seems to be the case, tho i suppose if i don't need to check if it's null i could just narrow it down to

log(Long.toString(getInventory().getAmount(IDs[0],IDs[1])));
Edited by senpai jinkusu
Link to comment
Share on other sites

 

you know im glad you mentioned the getInventory function, whenever i use just "inventory" it will return the correct number of ores on the first cycle then the next 3 it returns 0, either way here is the final code minus the removal of generics

<T extends ItemContainer>int getOreCount ( T itemContainer, int... IDs)

{
	if (itemContainer != null)
	 return (int)itemContainer.getAmount(IDs);
	return 0;

}
 public int onLoop() throws InterruptedException

{

  log(Integer.toString(getOreCount(getInventory(),IDs[0],IDs[1])));
return random(200, 300);
}
 

which so far is working fine and ended up being way more efficient than the old code, although Im not sure if checking for a null ItemContainer reference is necessary since that never seems to be the case, tho i suppose if i don't need to check if it's null i could just narrow it down to

log(Long.toString(getInventory().getAmount(IDs[0],IDs[1])));

 

The default instances of Bank, Inventory, Equipment etc. will never be null, so you don't need to nullcheck them.

"getInventory()" versus "inventory" is a matter of personal preference/convention. getInventory merely returns the inventory instance. It is the exact same thing.

 

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...