I was trying to use a combobox to show contents in a table. I wrote the code below, bu nothing displayed in the table.
Integer i = ((Destination) (jComboBox1.getSelectedItem())).getId();
query1 = entityManager.createQuery("SELECT d FROM Dayactivity d WHERE d.id=:Id");
query1.setParameter("Id", i);
java.util.Collection data = query1.getResultList();
list2.clear();
list2.addAll(data);
When I changed the code as below it returned data correctly and displayed in the table.
Integer i = ((Destination) (jComboBox1.getSelectedItem())).getId();
query1 = entityManager.createQuery("SELECT d FROM Dayactivity d WHERE d.id=:Id");
query1.setParameter("Id", 2);
java.util.Collection data = query1.getResultList();
list2.clear();
list2.addAll(data);
Why It is not working for the first code (i) but works for 2 in second code?
Can somebody help me to solve this, I am new to Java & NetBeans
Do one of the following:
if i is null then you need to change how you access the selected id of combobox as follows:
Integer i = ((Destination) jComboBox1.getSelectedIndex();
You need to check the argument of his method: