I am a newbe on JAVA and have been struggling with this for hours please help : Exception in thread "main" java.util.NoSuchElementException: No line found

Here is my code:

(assume that inFS, habitat, habitatData and i are already created/initialized, as they are initialized earlier in the code)

 

case "aquarium":

           

            habitat = inFS.nextLine();

           

            while(!habitat.contains("Aquarium")) {

               

               habitat = inFS.nextLine();

            }

           

            for (i = 1; i <= 4; i++) {

             

               habitatData = habitatData + habitat + "\n";

               habitat = inFS.nextLine();

            }

           

            habitatData = habitatData.substring(4, habitatData.length());

           

            return habitatData;

 

 

The habitats.txt file it is looking at is attached.  The two other habitats, using identical code to the above (with the exception of !habitat.contains(“Aquarium”) being “Bird” or “Penguin” instead) and they both work.

 

When I hit the “aquarium” case, I get:

 



                at java.util.Scanner.nextLine(Scanner.java:1540)

                at zooprogram.FileParser.habitatInfo(FileParser.java:246)

                at zooprogram.ZooProgramMenus.habitatMenu(ZooProgramMenus.java:173)

                at zooprogram.ZooProgramMenus.mainMenuDecision(ZooProgramMenus.java:68)

                at zooprogram.ZooProgram.main(ZooProgram.java:32)

<redacted>\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1

BUILD FAILED (total time: 4 seconds)

 

If I change the above code to replace for(i = 1; i <= 4; i++) with for(i=1; i <= 3; i++), the code works and returns:

 

Habitat - Aquarium

Temperature: Varies with output temperature

Food source: Added daily

 

I need the last line of the Habitat – Aquarium grouping (the 4th lilne), but I can’t get it to pull it and not error ohabitats.txt
LVL 1
NAMEWITHELD12Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zvitamConsultantCommented:
You should have a blank line after aquaruim you don't have so reach End of File.

I added and attched it to the post.
habitats.txt
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NAMEWITHELD12Author Commented:
Awesome !!!
That fixed it!  I hit enter and saved after the final line, but what I did not do was hit enter again to produce a blank line at the end of the text box.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.