when I run the task after putting input
it shows Null Pointer exception
Tell me the reason
Task has passed verification
Under discussion
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Sundaram
11 February 2019, 11:20
I also had the same problem. I changed the code like this and it worked.
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> list = new ArrayList<String>();
String s = reader.readLine();
while (s != null) {
if (!s.isEmpty()) {
list.add(s);}
else break;
s = reader.readLine();
}
0
Ritesh Kumar Mandal
8 January 2019, 04:00
BufferedReader.readLine() will return a null if the end of the stream is reached. So you want
while (line== null || line.isEmpty())
BufferedReader.readLine() will stop the reading at the first blank line. (If you don't have blank lines, then you don't ever need to call isEmpty().
0
Khurram
8 December 2018, 12:48
can you share the code?
0