Elements added to array in a function not available in the class, losing its values
<p>My program is supposed to simluate a shopping cart. One of the functions, it reads the item data from text document and stores the data such as price, item id, and item name, in the array. Once I try to access the array contents from the 'myClass' class below, it seems that the array contents that were added in the function disappeared. I was wondering if someone can help me figure out what is the correct way to use idArray which had elements added to it in a function, in myClass as attempted below? </p>

<p>Note: I added comments to the area to the array that isn't printing out as expected below.</p>

<p>I appreciate any help in advance.</p>

<pre><code>    public class MyClass extends JFrame{

            public String[] idArray = new String[10];
            public String[] recordArray = new String[10];
            public String[] priceArray = new String[10];

            public void openFile(){
                try{
                    x = new Scanner(new File("inventory.txt"));
                    x.useDelimiter(",|" + System.getProperty("line.separator")); 
                }
                catch(Exception e){
                    System.out.println("Could not find file");
                }
            }
            public void readFile(){
                int i=0;
                while(x.hasNext()){
                    idArray[i] = x.next();
                    recordArray[i] = x.next();
                    priceArray[i] = x.next();
                    i++;
                }
            }
            public MyClass(){


                /** Code to create GUI Here    **/


                //Process Item
                button1.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent e){
                      String y = item1.getText();
                      int numItems = Integer.parseInt(y);
                      MyClass obj = new MyClass();
                      obj.openFile();

                      //**ARRAY PRINTS OUT NULL AND DOES NOT PRINT OUT THE VALUES AQUIRED IN THE FUCNTION ABOVE**//
                      for(int i=0; i &lt; numItems; i++){
                          for(int g=0; g &lt; idArray.length; g++){
                                System.out.println(obj.idArray[g]);   
                          }
                       }
                   }
                });
         }      
    }
</code></pre>
