i m making a BMI calculator GUI which calcuates weight in corresponding to height shown on slider but there is some error in program. problem lies in following line

int value = slider.getValue();
        int weight=0;
	if (if buttonGroup.getSelected()=="Male")
	{
	weight=value/28;
	}
	else if (buttonGroup.getSelected()==Female)
	{
	weight=value/30;
	}
          System.out.println("weight");

Recommended Answers

In line 3 you have if(if "condition". Don't think there should be two ifs there.

You should not be testing a button group either. It is just something that can group radio buttons, checkboxes, etc... together. Test the individual checkbox/radiobutton(whatever you have) instead of the button group.

Try …

Jump to Post

All 2 Replies

The compiler error message tells you exactly what the error is and exactly which line it's on. "some error in program" is useless as a problem description.

In line 3 you have if(if "condition". Don't think there should be two ifs there.

You should not be testing a button group either. It is just something that can group radio buttons, checkboxes, etc... together. Test the individual checkbox/radiobutton(whatever you have) instead of the button group.

Try something like:

if(maleCheckbox.isSelected())

(this is assuming you are using checkboxes for your options)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.