+ 2

Why Scanner followed by a bufferedReader gives a Null pointer Exception ?

    int n = scanner.nextInt();         scanner.nextLine()         String[] unsorted = new String[n];         for (int i = 0; i < n; i++) {             String unsortedItem = br.readLine();             unsorted[i] = unsortedItem; } int n =Integer.parseInt(br readLine());         String[] unsorted = new String[n];         for (int i = 0; i < n; i++) {             String unsortedItem = br.readLine();             unsorted[i] = unsortedItem; } Just changing the 1st section of code with 2nd section solves the Exception in my Code , why is this happening ?? You can check the code ,by giving input : Length of Array , followed by its elements Eg - 4 1 2 3 4 https://code.sololearn.com/c3R2631V6N3f/?ref=app

30th Sep 2020, 3:17 PM
Mr.Curious
Mr.Curious - avatar
3 Antworten
+ 5
Never done it, but this might help. https://stackoverflow.com/q/7635917/10057029
3rd Oct 2020, 5:55 PM
John Wells
John Wells - avatar
+ 1
It didn't helped ,but I get to know something new.
3rd Oct 2020, 6:24 PM
Mr.Curious
Mr.Curious - avatar
0
LukArToDo or Danijel Ivanović , Can you explain this ?
20th May 2021, 5:41 AM
Mr.Curious
Mr.Curious - avatar