1

I have been trying to pass the arraylist into my rental menu class and extracting the relevant the movie title, id etc But i kept getting the error of incompatible type. Can someone please enlighten me as to my concept I've got wrong?

import java.util.ArrayList;
public class DVDManager {
    private ArrayList<DVD> group;
    private int Id;
    private String title;
    private char genre;

public DVDManager (){
    this.group = new ArrayList<DVD>();
}

public DVDManager (int Id, String title, char genre){
    this.Id = Id;
    this.title = title;
    this.genre = genre;
    this.group = new ArrayList<DVD>();
}
public int getId (){
    return Id;
}

public String getTitle(){
    return title;
}

public char getGenre(){
    return genre;
}

public void addDVD (int Id, String title, char genre){
    Id = group.size()+1;
    group.add(new DVD(Id, title, genre));
}

public ArrayList<DVD> retrievalAll(){  
    return group;
}
}

import java.util.*;
public class RentalMenu{
    private DVDManager dvdManager;

public RentalMenu(){
    dvdManager = new DVDManager();
}

public void processListAllDVDs(){

    DVDManager m1 = new DVDManager();

    //**ERROR IS THE LINE BELOW!!!!!!!!!!!!!**

    ArrayList<DVD> myList = m1.retrievalAll();
    //listDVDs = dvdManager.retrievalAll();
    for (int i=0; i<myList.size(); i++){

        DVDManager listDVDs = myList.get(i);
        System.out.println(listDVDs.getTitle + listDVDs.getGenre);
    }
}

public void readOption(){
    System.out.println("*=======================*");
    System.out.println("* Choose the following*  ");
    System.out.println("1) Add a new DVD         ");
    System.out.println("2) search a DVD         ");
    System.out.println("3) Rent a DVD         ");
    System.out.println("4) Show all DVD       ");
    System.out.println("5) EXIT       ");
    Scanner sc = new Scanner(System.in);

    int option = sc.nextInt();
    int movId = 1;

        if (option == 1){ 
            System.out.println("Enter movie title");
            sc.nextLine();
            String newMovie = sc.nextLine();
            System.out.println("Enter genre");
            char g = sc.nextLine().charAt(0);
            dvdManager.addDVD(movId, newMovie, g);
            processListAllDVDs();
        }

}
}
6
  • What line gives you the error? Commented Oct 22, 2013 at 17:29
  • 2
    ArrayList<DVD> contains DVD and not DVDManager. So myList.get(i); will give you a DVD. You are assigning it to DVDManager. Commented Oct 22, 2013 at 17:30
  • DVDManager listDVDs = myList.get(i) Commented Oct 22, 2013 at 17:31
  • Wrong types, unless DVD and DVDManager share some sort of class relationship. Commented Oct 22, 2013 at 17:33
  • sorry, i wish i knew how to include line number; Commented Oct 22, 2013 at 17:33

1 Answer 1

1
   for (int i=0; i<myList.size(); i++){
        DVDManager listDVDs = myList.get(i);      //here is the problem
        System.out.println(listDVDs.getTitle + listDVDs.getGenre);
   }

You need to change to

  DVD dvd= myList.get(i);
Sign up to request clarification or add additional context in comments.

3 Comments

required ArrayList<DVDManager> found ArrayList<DVD>
@TanHongJie Then how you declared like this private ArrayList<DVD> group;
WOOP! SOLVED the error lies in the ArrayList I've named Thanks bytecode!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.