No Such Element Exception?

The Solution to No Such Element Exception? is

It looks like you are calling next even if the scanner no longer has a next element to provide... throwing the exception.


Should be something like

boolean foundTreasure = false;

          foundTreasure = true;
          break; // found treasure, if you need to use it, assign to variable beforehand
    // out here, either we never found treasure at all, or the last element we looked as was treasure... act accordingly

~ Answered on 2011-11-07 02:23:26

Most Viewed Questions: