Java problem with textfield in GUI

Java problem with textfield in GUI
0

#1

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());
		
		}
		
		
	}
}

#2

what’s the exception? (full text please)


#3

it’s ok i solved this by myself!!! Thanks for responing though!!!


#4

What was your solution?


#5

mealsField = new JTextField();

I had text inside the mealsField , so when someone didn’t fill that the variable took the already existent text ! I removed it’s text and used this “if(mealsField.getText().length()==0)”