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;
}
4

1 回答 1

1

getCourtSportArrayList()似乎是您的 Sport 课程的一种方法。这个方法需要返回一个List<Court>它现在显然没有的。

结果该方法应如下所示:

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

旁注:除非您使用 ArrayList 的特定实现细节,否则您应该指定通用类型List<Court>而不是。ArrayList<Court>

于 2013-04-25T09:12:01.857 回答