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.

java.lang.NullPointerException

Featured Replies

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

  • Author
Just now, Token said:

Contains null values for empty slots

Ahhh good to know, tyvm

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

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

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

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 (: 

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.