Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Missing return statement

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Missing return statement

    Hello everyone

    I'm going out of my mind as to why this doesn't work, any help on the matter would be very helpful. I'll try and lay this out so its easy to read.

    It keeps saying missing return statement!


    thanks

     
    public boolean search(String searchString) {  
        int index = 0;
        boolean found = false;
               while(index < notes.size() && !found) {  
                     String note = notes.get(index);    
                     if(note.contains(searchString)) { 
               found = true;   
         }     
       else {     
           index++;    
        } 
       }  
      if(found) {  
          System.out.println("Found search term in note: " + notes.get(index));
     
        } else {        System.out.println("Search term not found.");    }}


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Missing return statement

    The method declares that it must return a boolean,
    public boolean search(String searchString)
    so you will receive a compile time error if the content of the function does not return a boolean value. To fix this, either change the return value to void,
    public void search(String searchString)
    or return a boolean value at the end of the method, something like this
    public boolean search(String searchString){
        boolean found = false;
    .....
        return found;
    }

  3. The Following User Says Thank You to copeg For This Useful Post:

    Stn (January 1st, 2011)

  4. #3
    Junior Member
    Join Date
    Jan 2011
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Missing return statement

    Wow return found; worked like a charm, i've actually got tears in my eyes i'm so happy!

    Thanks for your help.

Similar Threads

  1. what is wrong with my return statement??????
    By amr in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 13th, 2010, 07:55 PM
  2. Missing Return Statement in If-elseIf-else
    By chronoz13 in forum Loops & Control Statements
    Replies: 2
    Last Post: October 12th, 2009, 07:01 AM
  3. Prime number generator program missing return statement
    By 03EVOAWD in forum What's Wrong With My Code?
    Replies: 13
    Last Post: September 10th, 2009, 09:17 AM
  4. Error of "Class has no return statement"
    By mdstrauss in forum What's Wrong With My Code?
    Replies: 7
    Last Post: August 2nd, 2009, 12:00 PM
  5. [SOLVED] Java program to generate 10 random integers and then sum computed
    By Lizard in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 14th, 2009, 12:33 PM