I need help on how to check if mealsField is empty I did this “if(mealsField.getText().equals(null))” but i get an exception how to solve it ?
class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
String days = daysField.getText();
String hotelname = (String ) listView.getSelectedValue();
Hotel selectedHotel = null;
for(Hotel hotel: hotels2) {
if(hotel.getName().equals(hotelname)) {
selectedHotel = hotel ;
break;
}
}
Book book = null;
if(e.getSource().equals(storeButton)) {
int day = Integer.parseInt(days);
if(mealsField.getText().equals(null)) {
book = new SimpleBook(day);
}
else
{ String meals = mealsField.getText();
int meal = Integer.parseInt(meals);
book=new AllInclusive(day,meal);
}
selectedHotel.newBook(book);
System.out.println("Your book is done");
}
else {
JOptionPane.showMessageDialog(null,
"Total Charge : " +
selectedHotel.getName() + " is " + selectedHotel.totalCharge());
}
}
}