Re: method saying "no return statement" when there IS one

  • From: "Marlon Brandão de Sousa" <splyt.lists@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Sat, 23 Feb 2008 12:16:15 -0300

Alex,
You are, accordingly with what I can say, new to programming and this
is a common error. If you pay atention your method is declared as an
integer, so as java is a strongly typed language the compiler will
complain because of your return statement being empty. You can't
declare a method as integer and make it return no value. If you
declared it as an integer it has to return an integer value, it is
like a contract between you and the compiler. This is why variables
and methods have a type in their declarations and definitions.
Marlon

2008/2/23, Alex Hall <mehgcap@xxxxxxx>:
> I tried that and instead of saying "missing return statement" it
> said "missing return value".  I just put "return;" just before
> the final right-brace of the method.
>
> Have a great day,
> Alex
>
> > ----- Original Message -----
> >From: "Ken Perry" <whistler@xxxxxxxxxxxxx
> >To: <programmingblind@xxxxxxxxxxxxx
> >Date sent: Fri, 22 Feb 2008 21:30:26 -0800
> >Subject: RE: method saying "no return statement" when there IS
> one
>
>
>
> >If you have all the opening and closing braces the compiler might
> be
> >complaining because you don't have a sure return.  This is not
> normal for a
> >compiler but I don't know what compiler your using.  So you can
> try putting
> >a return at the end of the function right before the last } and
> that should
> >do the trick.
>
> >Ken
>
> >-----Original Message-----
> >From: programmingblind-bounce@xxxxxxxxxxxxx
> >[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Alex
> Hall
> >Sent: Friday, February 22, 2008 8:23 PM
> >To: programmingblind@xxxxxxxxxxxxx
> >Subject: Re: method saying "no return statement" when there IS
> one
>
> >Odd, I put all the braces in my original email.  I opened the
> method, two
> >for loops, an if statement, and an else statement and closed them
> all.  My
> >bn, on which I wrote that message, must have not liked it that I
> put them
> >all on separate lines; it seems to do odd things with punctuation
> just
> >before a new line if that punctuation is not connected to a word.
>
> >Have a great day,
> >Alex
>
> >> ----- Original Message -----
> >>From: "Fred Rains" <fred58@xxxxxxx
> >>To: <programmingblind@xxxxxxxxxxxxx
> >>Date sent: Fri, 22 Feb 2008 23:13:29 -0500
> >>Subject: Re: method saying "no return statement" when there IS
> >one
>
> >>Hi Alex, You have several opening braces with no closing brace.
> >Both "for"
> >>statements have an opening brace but no closing brace.  Also,
> >your "if" and
> >>"else" statements have opening braces with no closing brace.
>
> >>Fred
>
> >>----- Original Message -----
> >>From: "Alex Hall" <mehgcap@xxxxxxx
> >>To: <programmingblind@xxxxxxxxxxxxx
> >>Sent: Friday, February 22, 2008 10:46 PM
> >>Subject: method saying "no return statement" when there IS one
>
>
> >>> Hi all.  Yet again I have what to many of you is no doubt a very
> >simple
> >>> question, but it is not making sense.  I have a method that is
> >checking
> >>> collisions on a battleship grid.  It is an integer method that
> >returns 0
> >>> if a collision is detected and 1 if there is no problem.  The
> >compiler,
> >>> however, keeps saying that I am missing a return statement when
> >I clearly
> >>> have two, one in an if statement and the second in a related
> >else.  Here
> >>> is the method:
>
> >>> public static int checkCollisions(int[][] grid){
> >>> int i,j;
> >>> for(i=0;i<grid.length;i++){
> >>> for(j=0;j<grid[i].length;j++){
> >>> if(grid[i][j]<=2){
> >>> return 0;
>
> >>> else{
> >>> return 1;
>
>
>
>
>
> >>> Have a great day,
> >>> Alex
> >>> __________
> >>> View the list's information and change your settings at
> >>> //www.freelists.org/list/programmingblind
>
>
> >>__________
> >>View the list's information and change your settings at
> >>//www.freelists.org/list/programmingblind
>
>
> >__________
> >View the list's information and change your settings at
> >//www.freelists.org/list/programmingblind
>
> >__________
> >View the list's information and change your settings at
> >//www.freelists.org/list/programmingblind
>
>
> __________
> View the list's information and change your settings at
> //www.freelists.org/list/programmingblind
>
>


-- 
When you say "I wrote a program that crashed Windows," people just
stare at you blankly and say "Hey, I got those with the system, for
free."
Linus Torvalds
__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: