Link to home
Start Free TrialLog in
Avatar of komlaaa
komlaaa

asked on

return value

Hi,
if the user  has not enter anything, i want to force him to enter the val. That is why what i am trying to do in this code. but i am getting the error:

sss/StudentPanel.java [206:1] missing return statement
    }

How can i fix that?

 public String getLast()
    {
        String last = (String)lastCombo.getSelectedItem();
        if(last == null || last == "")
        {
            JOptionPane.showMessageDialog(this,
            "Plase Enter Student lastName",
            "Error",JOptionPane.INFORMATION_MESSAGE );

        }
        else
        {
            return last.trim();
        }
    }
SOLUTION
Avatar of Webstorm
Webstorm

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Webstorm
Webstorm

You need to test if getLast() return null :

    if (getLast()!=null) /* close the dialog window */
Avatar of komlaaa

ASKER

1.) if (getLast()!=null) /* close the dialog window */
why should i close the dialog, the JOptionPane dialog is opened only when getLast() == null or Not, --- i think so.

2.) if(last == null || last == "")
do u think i should check for empty string ( last == "")
Avatar of CEHJ
public String getLast() {
      String last = (String)lastCombo.getSelectedItem();
      do {
            JOptionPane.showMessageDialog(this, "Please select Student last name", "Error", JOptionPane.INFORMATION_MESSAGE);
      } while(last == null);
      return last;
}      
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:-)