Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Calculator program: BufferedReader, Stream closed  RSS feed

 
Ranch Hand
Posts: 132
5
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy Ranchers!

I am preparing for my OCP v8 exam. I am just playing with writing simple programs. So I wrote a basic console calculator program. I made all my methods are static for my convience. I am getting a runtime exception.

Don't be afraid of size of the program. Anyone can understand it. Try it and help me to figure out what is wrong here. Cheers!




Here is the exception that is getting logged in my Eclipse console IDE
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your readTextLine, when you read a line, you are closing the System.in stream by closing the BufferedReader (which gets closed because of try-with-resources block). So, for the next line, you get that exception.
By the way, when you get stacktrace, it shows the line numbers - which you can use to pinpoint the code causing the exception.
 
Marshal
Posts: 59742
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are doing the reading in the wrong place. Create yourself a utility class to do all your keyboard reading and never close whatever you are using to read from System.in.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!