It says that I'm receiving the error at line 506 which is the one saying
firstTxt.setText(newPerson.getFirstname());
Here is the first two lines of error code: Exception in thread
AWT-EventQueue-0" java.lang.NullPointerException at
dataawaredatajava.JFrame.addButtonActionPerformed(JFrame.java:506)
This only happens whenever I click on the "Add?" button or addButton. I use a similar method of casting my object with my update button, but that seems to work perfectly fine!
private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {
switch (addButton.getText()) {
case "Add New Person":
lstPerson.clearSelection();
blockForAddOrUpdate(true);
addButton.setEnabled(true);
addButton.setText("Add?");
break;
case "Add?":
Person newPerson = (Person)lstPerson.getSelectedValue();
firstTxt.setText(newPerson.getFirstname());
lastTxt.setText(newPerson.getLastname());
dobTxt.setText(newPerson.getDob());
occupationTxt.setText(newPerson.getOccupation());
marriedChB.setSelected(newPerson.getMarried());
noOfKidsJSp.setValue(newPerson.getNumberofkids());
dataAwareDataJavaPUEntityManager.getTransaction().begin();
dataAwareDataJavaPUEntityManager.persist(newPerson);
dataAwareDataJavaPUEntityManager.getTransaction().commit();
addButton.setText("Add New Person");
blockForAddOrUpdate(false);
personList.add(newPerson);
lstPerson.setSelectedValue(newPerson, true);
break;