#Crashing with NullPointerException

23 messages · Page 1 of 1 (latest)

rugged hedge
#

I can't find the reason why I'm crashing with NullPointerException on method "slot.getHasStack()" because I've made a check to check if object "slot" is null, does someone know how I fix this?

sick needleBOT
#

This post has been reserved for your question.

Hey @rugged hedge! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

rugged hedge
#

I think I have to learn how Java works 💀

weary trout
#

I guess java while trying to verify your slot reference encounter that it was null and just print out the exeption and terminate

#

use try-catch and with the catch you do nothing

#

something like:

#
 **your code** 
}catch(NullPointerException e){
**this code will execute if pointer is null**
}
minor stream
minor stream
sick needleBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.

rugged hedge
cosmic ridge
#

slot.getHasStack() itself is throwing the npe

rugged hedge
#

is this the problem?

minor stream
minor stream
#

idk what that is. that seems different from the line showed previously

#

getHasStack will throw an NPE if getStack returns null

#

that's important to understand

rugged hedge
#

ok

minor stream
#

futhermore, if your inventory is null then getStack itself will throw an NPE

rugged hedge
#

I think like you said, something went wrong and inventory got null. I will look at it, thanks!

sick needleBOT