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();
        }
    }
komlaaaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

WebstormCommented:
       {
            JOptionPane.showMessageDialog(this,
            "Plase Enter Student lastName",
            "Error",JOptionPane.INFORMATION_MESSAGE );
            return null;  // <----
        }
        else
        {
            return last.trim();
        }
0
WebstormCommented:
You need to test if getLast() return null :

    if (getLast()!=null) /* close the dialog window */
0
komlaaaAuthor Commented:
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 == "")
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

CEHJCommented:
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;
}      
0
CEHJCommented:
This is better actually:

public String getLast() {
      String last = (String)lastCombo.getSelectedItem();
      while(last == null) {
            JOptionPane.showMessageDialog(this, "Please select Student last name", "Error", JOptionPane.INFORMATION_MESSAGE);
      }
      return last;
}      
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
:-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.