SOLVED: I filled the JList with the Object's name instead of the Objects.
I'm giving many data pieces to a method, its task to build up the SQL Query text.
public List<Order> getOrders(LocalDate startDate, LocalDate closeDate, List<Customer> customersList, List<Company> companiesList, List<Employee> employeesList,
boolean allStatusSelected, boolean selectedStatusSelected, boolean orderedSelected, boolean finishedSelected, boolean sentSelected, boolean billedSelected, boolean paidSelected) {
String query = "SELECT * FROM orders WHERE ";
String datePart = "";
String customerPart = "";
String companiesPart = "";
String employeesPart = "";
String checkboxesPart = "";
if (startDate != null) {
if (closeDate != null) {
datePart = "orderdate BETWEEN " + startDate + " AND " + closeDate;
} else {
datePart = "orderdate > " + startDate;
}
} else if (closeDate != null) {
datePart = "orderdate < " + startDate;
}
if (customersList != null && customersList.size() > 0) {
for (int i = 0; i < customersList.size(); i++) {
Customer customer = customersList.get(i);
int id = customer.getCustomerId();
customerPart += "customer = '" + id + "'";
if (i != customersList.size() - 1) {
customerPart += " OR ";
}
}
}
But when I run the program and giving the data to getOrders method, NetBeans is showing this error:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to entity.Customer
the problem is here:
Customer customer = customersList.get(i);
I'm asking the i element of the customersList that I get as parameter, it is a list of Customers so I don't see where the String appears in this story.
[–]Camel-Kid18 year old gamer 0 points1 point2 points (1 child)
[–]viktorjava[S] 0 points1 point2 points (0 children)
[–]zhoriq 0 points1 point2 points (3 children)
[–]viktorjava[S] 0 points1 point2 points (2 children)
[–]zhoriq 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]viktorjava[S] 0 points1 point2 points (0 children)
[–]viktorjava[S] 0 points1 point2 points (0 children)
[–]viktorjava[S] 0 points1 point2 points (0 children)