Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

getItems(); throws NullPointerException

Featured Replies

  • Author

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

 

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.

 

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.