1

I'm using BlueJ as an IDE and whenever I try to compile this Java code it gives me an error: incompatible types highlighting the brackets of:

s.getCourtSportArrayList() 

Why this is happening?

public void showCourtBookings()
{
 for(Sport s : sportList)
 {
   for(Court c : s.getCourtSportArrayList() )
   {
     System.out.println("Court: " + c.getCourt);
     int i;
     i=1;
     for(Booking b : c.getBookings())
     {  
         System.out.println("Booking: " + i + "Start Time: " + b.getTimeStart() + "End Time :" + b.getEndTime());
         i = i + 1;
     }
   }
 }  
}

This is a class Club, it contains two ArrayLists;

private ArrayList<Member> MemberList;
private ArrayList<Sport> sportList;

The Sport class has the following ArrayList:

private ArrayList<Court> CourtList = new ArrayList<Court>();

The Court class has these ArrayLists:

private ArrayList<Booking> listBooking;

Hopefully you can point me in the right direction. Thanks!

Edit: this is the code,

public ArrayList getCourtSportArrayList()
{
  return CourtList;
}
2
  • 1
    Shouldn't c.getCourt be c.getCourt()? Commented Apr 25, 2013 at 9:11
  • 1
    What is the code of getCourtSportArrayList()? Commented Apr 25, 2013 at 9:11

1 Answer 1

1

The getCourtSportArrayList() seems to be a method of your Sport class. This method needs to return a List<Court> which it apparently does not right now.

in result the method should look like this:

public List<Court> getCourtSportArrayList()
{
   return CourtList;
}

Side note: You should specify the generic Type List<Court> instead of ArrayList<Court> unless you use specific implementation details of ArrayList.

Sign up to request clarification or add additional context in comments.

4 Comments

It does though... or did I write it incorrectly? public ArrayList getCourtSportArrayList() { return CourtList; }
Java does not magically add getter and setter methods to your private member objects like private ArrayList<Court> CourtList. You need to code this explicitly.
You need to specify the type! public List<Court> getCourtSportArrayList() { return CourtList; }
I've had to find a workaround for using ArrayLists since Iv'e been declaring them incorrectly in the method signatures this entire time. Thankyou :)

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.