title: Creating an array of a class inside of another class
body: <p>This is a simplified version of a problem I am having. I'm trying to create an an array of ProduceItem inside of class database. I have outlined the warnings and problems I've encountered in my attempts. Thank you for your help in advance.</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  public class Test{
      public static void main(String[] args) {
      //attempt 1: 
      //database a;
      // Warning: local variable a is not used.
      // Warning: Null pointer access: The variable a can only be null at this location
  
      //attempt 2:
      //database a;
      //a.test[0].setCode(2);
      //local variable has not been initialize
  
      //results in attempt 2 part 2
      //database a = null;
      //a.test[0].setCode(2);
      //Null pointer access: The variable a can only be null at this location
      //When I run it, Exception in thread "main" java.lang.NullPointerException 
      //at Test.main(Test.java:8) 
      //\which is a.test[0].setCode(1); 
      }
  public class ProduceItem{
    private int code;
    public ProduceItem(){
       code = 0;
    }
    public int getCode(){
       return code;}
  
    public void setCode(int a){
       code = a;}
  public class database{
    ProduceItem[] test;
    }
  </code></pre>