1.11M Members

For Each Loop

 
0
 

Hi,

Why does this piece of code throw me an error saying: cannot return a value from method whose result type is void?

public void orderTotal()
       {
       int total;

       for (Order filename: Orders) {

         total = filename.getQuantity(); 


        }

        return total;
   }
 
0
 

Please post the full text of the error message that shows where the error occurs.
What statement causes the exception?

method whose result type is void?

The posted method is defined with return type of void on line 1. It can not return a value on line 12.
Change its return type to be the same type as total if you want to return a value.

BTW total won't be an accumulation of values, it will hold the last value received in line 7

 
0
 

The error occurs on the return total; The getQuantity() method is being called from another class.

 
0
 

We cross posted. See my last post.

 
0
 

Thank you, I can't believe I didn't see that.

Question Answered as of 1 Year Ago by NormR1
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article