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?

Recommended Answers

All 2 Replies

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

commented: Thanks +2

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(); 
			}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.