• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unreachable statement  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cannot see why I am getting an 'Unreachable statement' error on 'return -1;' on line 13126.

I am also getting a 'missing return statement' error on the very last line.

 
author & internet detective
Marshal
Posts: 37518
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John,
John,
Welcome to CodeRanch! That's a lot of code in a very long method. Will get back to that.

Consider these two shorter examples that illustrate your problems:

The for loop in this example runs forever. The compiler has no way of knowing that the return statement inside the loop gets run. We can see that. But from the compiler's point of view, the if statement might not run and the loop goes on forever. This is what is going on in your code too. The compiler doesn't know that the loop will ever end so it considers the code unreachable.


In this example, there are two branches. The try block has a return statement. The catch block does not. Just like in your code, the compiler is upset no value gets returned for this second case.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37518
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The length of the code makes it hard to read. Consider making some smaller methods so you can extract logic into them.

For example:


Then you can call these smaller methods from your large method and make it easier to read.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And also give your variables names which reflect what they mean; that code is almost impossible to understand otherwise.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!