Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

return value

Posted on 2005-03-29
6
Medium Priority
?
230 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
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

578 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