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
#static block cause null pointer exception
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
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.
You have a circular dependency
SlashCommandManager needs to create a Help before existing
but Help needs SlashCommandManager to exists before existing itself
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
i don't get this
like using one line?
you are creating the help message on startup
create the help message when the user ask instead
is it still good if everytime the message requires for loop to create
if i create it on startup maybe it can save some time to create it again?
this isn't a good idea
for the reason explained before
and please stop abusing static @valid breach
yeah I'll remove them
when should I use them though
mostly only for constants and utility methods
utility methods?
oh those that doesn't require to make a new object
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