Skip to content
Advertisement

How do I transfer my parsed array data from one class to another?

My program uses Picocli to parse XML data and store it in an ArrayList. For some reason, the information gets removed when I try to access it from another class.

I run the code below, and it shows the elements just fine:

JavaScript

So I try to access sourceArray from another class:

JavaScript

and results in variables being [], thus not able to transfer data to another class.

Picocli setup snippet:

JavaScript

Advertisement

Answer

The static context of the SourceSentences.main() is lost once you run the getArrayElements.main() method. The parsing of your XML data never happened as far as getArrayElements.main() was concerned.

You need to call the translate method from inside the getArrayElementsmain function.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement