0
List result = q.list();
		if (result.isEmpty()){
			System.out.println("No Projects");
		}
		else{
			for(Object object : result){
				Project p = (Project) object;
				System.out.println(p.getName()+" worked on by "+p.getEmployees().getName());
			}
		}

error :
CompanyReports.java:303: cannot find symbol
symbol : method getName()
location: interface java.util.List<Employee>
System.out.println(p.getName()+" worked on by "+p.getEmployees().getName());
^
1 error

Can anyone help what is my stupid mistake here? And how can I deal with it?

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by sfar_furqan
1

Seems that p.getEmployees() is returning a List. You will have to iterate that list and than use the getName() method for each 'Employee' object in the list

Votes + Comments
Thanks
0

Seems that p.getEmployees() is returning a List. You will have to iterate that list and than use the getName() method for each 'Employee' object in the list

Thanks man I got it :D

[code=java]for(Object object : result){
				Project p = (Project) object;
				System.out.print(p.getName()+" worked on by ");
				Iterator itr = p.getEmployees().iterator();
				if(!(itr.hasNext())){
					System.out.print("no employees.");
				}
				while(itr.hasNext()){
					Employee emp = (Employee) itr.next();
					System.out.print(emp.getName()); 
					if (itr.hasNext()){
						System.out.print(", ");
					}
				}
				System.out.println(); 
			}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.