Home Java Java-get-example Java error missing return statement



Java error missing return statement
Posted on: November 4, 2008 at 12:00 AM
Java error missing return statement are those error in Java that occurred when a programmer forget to write a return statement inside the conditional clauses. method with a non-void return provides you an object of the specific type.

Java error missing return statement

     

Java error missing return statement are those error in Java that occurred when a programmer forget to write a return statement inside the conditional clauses. method with a non-void return provides you an object of the specific type.

Understand with Example

In this Example we want to describe you a code that explain you  in understanding Java error missing return object. For this we have taken a non void method 'operation( )'that return you an int type and this method include a  for loop clause that check the condition If there is anything other than void method, then you must specify the return type in it. The given below code is missing a return statement in the non-void method so, whenever the compiler execute the code the code returns a missing return statement error.

There are two way to resolve this problem-

1)Change the non-void method to a void method.

2)Add or write a return expression to the non-void method.

Missingreturnstatement.java


public class Missingreturnstatement {

  public int operation(int num) {
  for (int i = 0; i <= num; i++) {
  System.out.println(i);
  }
  
  }

  public static void main(String[] args) {
  Missingreturnstatement m = new Missingreturnstatement();
  m.operation(7);
  }
}


Output

Compiling source file to /home/girish/NetBeansProjects/errors/build/classes
/home/girish/NetBeansProjects/errors/src/
Missingreturnstatement.java:
9: missing return statement

  }
error
BUILD FAILED (total time: seconds)


To resolve this error you have to give the return statement as return num;

Download code

Related Tags for Java error missing return statement:
javacerrorideobjectiomethodgettypeconditionalvistatereturnidwriteprogrammerifconditionforwithprogramstatementtoramvoidcissieitdesmissingusepeinnostamntsidsideosclauseosjclesspecemoidmeobjprowhensurnspatisisshaarstatccspecificvausesssrithcondavsthatforgejeorgprmismindonogronon


More Tutorials from this section

Ask Questions?    Discuss: Java error missing return statement  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.