title: For-Each Loop Incompatible Types
body: <p>I'm working on a project that creates a virtual database for films. I have two classes: MovieEntry (for the individual movie entry) and MovieDatabase (the larger class that contains the database and allows for additions, etc.) I'm getting a few errors, the first of them being that in the searchTitle method it says that Database is of an incompatible type. Can anyone tell me how to do these for-each loops? I read the book and I thought the ArrayList was supposed to go there but apparently not.</p>
  
  <pre><code>**import java.util.ArrayList;
  import java.util.Scanner;
  import java.io.*;
  public class MovieDatabase
  {
     private ArrayList&lt;MovieEntry&gt; Database = new ArrayList&lt;MovieEntry&gt;();
     public MovieDatabase(){
         ArrayList&lt;MovieDatabase&gt; Database = new ArrayList&lt;MovieDatabase&gt;(0);
      }
  
     public int countTitles() throws IOException{
     Scanner fileScan;
     fileScan = new Scanner (new File("movies.txt"));
     int count = 0;
     String movieCount;
     while(fileScan.hasNext()){
         movieCount = fileScan.nextLine();
         count++;
      }
     return count;
  }
  
     public void addMovie(MovieEntry m){
         Database.add(m);
      }
  
     public ArrayList&lt;MovieEntry&gt; searchTitle(String substring){
         for (String title : Database)
            System.out.println(title);
            return null;
      }
  
     public ArrayList&lt;MovieEntry&gt; searchGenre(String substring){
         for (String genre : Database)
            System.out.println(genre);
            return null;
      }
  
     public ArrayList&lt;MovieEntry&gt; searchDirector (String str){
         for (String director : Database)
            System.out.println(director);
            return null;
      }
  
     public ArrayList&lt;MovieEntry&gt; searchYear (int yr){
         ArrayList &lt;String&gt; yearMatches = new ArrayList&lt;String&gt;();
         for (String s : Database)
         s.getYear();
          if(yearMatches.contains(y) == false){
             yearMatches.add(y);
          }
         return yearMatches;
      }
  
     public ArrayList&lt;MovieEntry&gt; searchYear(int from, int to){
         ArrayList &lt;String&gt; Matches = new ArrayList&lt;String&gt;();
         for(Student s : movies);
            Matches.add();
         return Matches;
      }
  
     public void readMovieData(String movies){
         String info;
         try{
             Scanner fileReader = new Scanner(new File(movies));
             Scanner lineReader;
  
             while(fileReader.hasNext()){
                 info = fileReader.nextLine();
  
                 lineReader = new Scanner(info);
                 lineReader.useDelimiter(":");
  
                 String title = lineReader.next();
                 String director = lineReader.next();
                 String genre = lineReader.next();
                 int year = lineReader.nextInt();
              }
  
          }catch(FileNotFoundException error){
              System.out.println("File not found.");
  
          }catch(IOException error){
              System.out.println("Oops! Something went wrong.");
          }
      }
  
  
  
   public int countGenres(){
      String g;
      ArrayList &lt;String&gt; gList = new ArrayList&lt;String&gt;();
      for(Student s : movies){
        String g = s.getGenre();
        if(gList.contains(g) == false){
          gList.add(g);
        }
        return gList.size();
      }
      }
      public int countDirectors(){
       ArrayList &lt;String&gt; dList = new ArrayList&lt;String&gt;();
       for(Student s : movies){
          String d = s.getDirector();
          if(dList.contains(d) == false){
              dList.add(d);
          }
          return dList.size();
       }
  
       }
  
      public String listGenres(){
          ArrayList &lt;String&gt; genreList = new ArrayList&lt;String&gt;();
  
      }
  
  }**
  </code></pre>