#static block cause null pointer exception

1 messages · Page 1 of 1 (latest)

valid breach
#

right now i got two classes, and i created static variables. When I called SlashCommandManager class then the for loop of Help class throws NullPointerException, any idea why the values are null? I thought I already initialized the arraylist.
What I wanted to do is to only initialize helpEmbedMessage once since creating it will create for loops, and it is a frequently used variable

dusky lodgeBOT
#

<@&987246399047479336> please have a look, thanks.

dusky lodgeBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

brave tide
#

SlashCommandManager needs to create a Help before existing

#

but Help needs SlashCommandManager to exists before existing itself

valid breach
#

ohh

#

wait so when Help is called the array is null

brave tide
#

the list is null yes

#

since Help is created during the creation of the list

#

and so the list doesn't exist yet

#

as a rule of thumbs, avoid to use static please

#

and for the case of help, create the message dynamically instead if creating it at the start

valid breach
#

like using one line?

brave tide
#

create the help message when the user ask instead

valid breach
#

if i create it on startup maybe it can save some time to create it again?

brave tide
#

for the reason explained before

valid breach
#

ohh

#

icic

#

thanks

brave tide
#

and please stop abusing static @valid breach

valid breach
#

yeah I'll remove them

valid breach
brave tide
valid breach
#

oh those that doesn't require to make a new object

muted bison
#

That and ideally methods which are stateless (only act on input of the parameters), so you're sure that the method itself cannot create another cyclic dependency by itself