title: How do I add this to an arraylist within a static method?
body: <p>I'm learning the ropes with Java and I've hit a snag with ArrayLists. The gist of my program is to take some user input parameters, create a class Foo with those parameters, and then add it to an arraylist. The problem is, it complains that I can't reference a non-static type from a static method. The only examples I can find online deal with adding constants ("Cat", "5.0" etc) to arraylists which doesn't really help me.   </p>
  
  <p>I put the gist of my code below. I've moved the arraylist off to its own class Bar and added an add method which just does arraylist.add(foo), if only as a crapshoot to make it work (it doesn't). I omitted the loop but it loops a number of times after the definitions, so the arraylist gets populated. </p>
  
  <pre><code>public class MainClass{
  
  public static void main(String[] args){
  Scanner scanner = new Scanner(System.in);
  int a, b;
  
  a = scanner.nextint();
  b = scanner.nextint();
  
  Foo foo = new Foo(a, b);
  Bar.add(foo); //Complains here
  }
  }
  </code></pre>
  
  <p>Edit: Here is Bar explicitly</p>
  
  <pre><code>import java.util.ArrayList;
  public class Bar{
  private ArrayList list = new ArrayList();
  
  public void add(Foo foo){
      list.add(foo);
  }
  }
  </code></pre>
  
  <p>If it helps, the object foo isn't changed after creation. </p>
  
  <p>How do I get around this? Thanks in advance for any help.</p>