?
Solved

return value

Posted on 2005-03-29
6
Medium Priority
?
224 Views
Last Modified: 2010-03-31
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();
        }
    }
0
Comment
Question by:komlaaa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 13

Assisted Solution

by:Webstorm
Webstorm earned 100 total points
ID: 13653722
       {
            JOptionPane.showMessageDialog(this,
            "Plase Enter Student lastName",
            "Error",JOptionPane.INFORMATION_MESSAGE );
            return null;  // <----
        }
        else
        {
            return last.trim();
        }
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 13653753
You need to test if getLast() return null :

    if (getLast()!=null) /* close the dialog window */
0
 

Author Comment

by:komlaaa
ID: 13654116
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 86

Expert Comment

by:CEHJ
ID: 13654140
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
 
LVL 86

Accepted Solution

by:
CEHJ earned 400 total points
ID: 13654163
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 13654679
:-)
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question