#Crashing with NullPointerException
23 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @rugged hedge! Please use
/closeor theClose Postbutton 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.
I think I have to learn how Java works 💀
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**
}
can you verify that it's actually on that line?
it's generally not a good idea to catch unchecked exceptions, especially NullPointerExceptions as they are usually avoidable. if you want to check if a value is null, then you should use an if statement like the user is doing.
💤 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.
the error message points actually to this method...
slot.getHasStack() itself is throwing the npe
is this the problem?
yep now you need to check if ItemStack returned from getStack is null
?? how
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
ok
futhermore, if your inventory is null then getStack itself will throw an NPE
I think like you said, something went wrong and inventory got null. I will look at it, thanks!
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.