title: Java Object Array Foreach Method Access
body: <p>After developing in PHP for a long time I have decided to step into Java. Comfortable in OOP methodology and all that, I'm trying to start off at that point within java, but I'm getting hung up on passing out my arraylist object into a for statement to be printed back out using the Item class methods.</p>
  
  <p><em>HelloInvetory.java</em></p>
  
  <pre><code>package helloInventory;
  
  import java.util.Arrays;
  
  public class HelloInventory {
  
      /**
       * @param args
       */
      public static void main(String[] args) {
          // TODO Auto-generated method stub
          Object InvetoryItems;
  
          Inventory inv = new Inventory();
          inv.createItemObj(101, "camera", "Used camera that I bought off of a homeless guy.", 500);
          InvetoryItems = inv.getAllInventoryItems();
  
          for(Object item : InvetoryItems){
                 System.out.println(item.getItemName());
          }
  
          System.out.println("Done");
      }
  
  }
  </code></pre>
  
  <p><em>Inventory.java</em></p>
  
  <pre><code>package helloInventory;
  
  import java.util.*; 
  
  /**
   * Tracks and maintains all items within the inventory
   * @author levi
   *
   */
  public class Inventory {
  
      List&lt;Object&gt; InventoryItems = new ArrayList&lt;Object&gt;();
  
      /*
       * create object from Items class
       * and insert into Object[] array.
       */
      public void createItemObj(int sku, String name, String descriptor, float price) {
          Items item = new Items();
          item.setSku(sku);
          item.setItemName(name);
          item.setItemDescription(descriptor);
          item.setItemPrice(price);
  
          this.setInventoryItems(item);
      }
      public Object getAllInventoryItems() {
          //return InventoryItems;
           return this.InventoryItems.toArray();
      }
  
      public void setInventoryItems(Object inventoryItems) {
          //InventoryItems.add(inventoryItems);
           this.InventoryItems.add(inventoryItems);
      }
  }
  </code></pre>
  
  <p><em>Items.java</em></p>
  
  <pre><code>package helloInventory;
  /**
   * Class object to hold each item details
   * @author levi
   *
   */
  public class Items {
  
      int sku;
      String itemName;
      String itemDescription;
      float itemPrice;
  
      public int getSku() {
          return sku;
      }
      public void setSku(int sku) {
          this.sku = sku;
      }
      public String getItemName() {
          return itemName;
      }
      public void setItemName(String itemName) {
          this.itemName = itemName;
      }
      public String getItemDescription() {
          return itemDescription;
      }
      public void setItemDescription(String itemDescription) {
          this.itemDescription = itemDescription;
      }
      public float getItemPrice() {
          return itemPrice;
      }
      public void setItemPrice(float itemPrice) {
          this.itemPrice = itemPrice;
      }
  
  }
  </code></pre>
  
  <p>Where I am stuck is within the HelloInventory.java</p>
  
  <pre><code>for(Object item : InvetoryItems){
                 System.out.println(item.getItemName());
          }
  </code></pre>
  
  <p>IDE (Eclipse) gives me the error "Can only iterate over an array or an instance of java.lang.Iterable". Is there something extra I need, or I'm I going around this totally the wrong way in Java? Correct example would be helpful.</p>
  
  <p>Best,
  Levi</p>