• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

BufferedReader is there method while next exist?

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, Java genius!
Can anyone help please is there a method on a buffereReader while the next on the file exist do when there is no new lines finish. I searched for that but could not find smth. similar do you know how to do that. This is my code I wanted to do like while there is a new line in the file put it in an arrayList when there is no more lines stop.



Equation.txt

2+2
4/3
15*2
14$5

Ok, I added
but now it shows NullPointerException when I debugged it it does two tmes and then throws Exception I think it is because there is no an increasement like int i =0; i++
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
there isn't one in the api, and the 1st five examples i found showed how to do it.

adding example into your search is very helpfull.
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just check the return value of the readLine() method. It will return null when it reaches the end of the file.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anissa Pary wrote:

but now it shows NullPointerException



The only way that code can throw NPE is if br is null or equations is null. And that can only happen if you didn't initialize them, or if you explicitly set them to null. It will not happen from reaching the end of the file. So either you are making one of those things be null, or the NPE is coming from somewhere else.
 
Wendy L Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you aren't working in an IDE so can't debug, System.out.println() is your friend print out the variables the line before you use them.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic