title: java.lang.Error: Unresolved compilation problem for singelton class
body: <p>I have a program with two classes that declared as singeltone classes.
  When I am trying to run the program I am getting a java.lang.Error: Unresolved compilation problem in the line that getting the instance of the singeltone class and I don't understand why.</p>
  
  <p>The error:</p>
  
  <pre><code>Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
  
      at Model.Recommender.getInstance(Recommender.java:22)
      at Model.Library.&lt;clinit&gt;(Library.java:21)
      at Controller.MainClass.main(MainClass.java:69)
  </code></pre>
  
  <p>The error line in the Recommender class:</p>
  
  <pre><code>public static Recommender getInstance() {
  </code></pre>
  
  <p>And the class declared this way:</p>
  
  <pre><code>public class Recommender {
  
      private static Recommender recommender; //a recommender
      private HashSet&lt;Reader&gt; libraryReaders; //a hash set of all of the library readers
  
      //constructor to initialize the fields
      private Recommender() 
      {
          libraryReaders = new HashSet&lt;Reader&gt;();
      }
  
      //method to make the class a singleton class
      public static Recommender getInstance() {
          if(recommender == null) //check that a instance of this class doesn't exist
          {
              recommender = new Recommender(); //creates a new instance
          }
          return recommender; //return the instance that was created
      }
  }
  </code></pre>
  
  <p>The error line in the library class:</p>
  
  <pre><code>private static Recommender recommender = Recommender.getInstance();
  </code></pre>
  
  <p>And the class declared this way:</p>
  
  <pre><code>public class Library {
  
      private static Library library; //a library
      private static Recommender recommender = Recommender.getInstance();
      private HashSet&lt;Reader&gt; readers;
      private HashSet&lt;Author&gt; authors;
      private HashSet&lt;LibraryItem&gt; items;
  
      //constructor to initialize the fields
      private Library() {
          readers = new HashSet&lt;Reader&gt;();
          authors = new HashSet&lt;Author&gt;();
          items = new HashSet&lt;LibraryItem&gt;();
      }
  
      //method to make the class a singleton class
      public static Library getInstance() {
          if(library == null) //check that a instance of this class doesn't exist
          {
              library = new Library(); //creates a new instance
          }
          return library; //return the instance that was created
      }
  }
  </code></pre>
  
  <p>The error in the Main class:</p>
  
  <pre><code>LibrarySys = Library.getInstance();
  </code></pre>
  
  <p>I am creating an instance of recommender in the library class and an instance of library in the main class. Why am I getting this error?</p>