#List is null even if it wasn't

1 messages ยท Page 1 of 1 (latest)

amber jewel
#

In my Main class, i just want to store the args passed in the main method.
If i log the list in the console right after i set it it prints the argument so it's actually stored.

public class Main {

   public static List<String> arguments = new ArrayList<>();

   @DontObfuscate
   public static void main(String[] args) throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, IllegalAccessException {
      arguments = Arrays.stream(args).toList();
      System.out.println(arguments);
  ...```

But if I log it in another class 5 seconds later it is an empty list. why?
lime tulipBOT
#

โŒ› This post has been reserved for your question.

Hey @amber jewel! 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.

rich vine
#

Hi @amber jewel , if you search for "arguments" in your project, is that line the only one that sets a value in it?

amber jewel
#

yes it is the only one where i set it

rich vine
#

And when you logged it somewhere else you get "null" not an empty list?

amber jewel
#

an empty list, i'm stupid i don't know why i wrote null ๐Ÿ˜… ๐Ÿ™ˆ

rich vine
#

How are you logging in the other class? Could you please share the code where you are accessing "arguments"?

amber jewel
#

the line is System.out.println(String.valueOf(Main.arguments));

#

and the argument variable is called nowhere else

rich vine
#

I can't think on anything obvious... I would suggest to use the debugger tool and go line by line checking that variable to see where it's changing the value

#

Do you have the code in a public repository?

amber jewel