I followed this code and for some reason its showing the error in the image. i cant figure out whats wrong, please help!

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Scanner sc = new Scanner(System.in);
ArrayList <Student> students = new ArrayList<Student>();

ArrayList <Student> courses = new ArrayList<Student>();

// Method to read the file contents and stores it in
// instance arrays
void readStudents()
{
// Scanner class object declared
Scanner readStuF = null;

// try block begins
try
{
// Opens the file for reading
readStuF = new Scanner(new File("student.txt"));

// Loops till end of the file to read records
while(readStuF.hasNextLine())
{
String stu = readStuF.nextLine();
String []eachStu = stu.split(" ");

students.add(new Student(eachStu[0], eachStu[1],
eachStu[2], Long.parseLong(eachStu[3]),
Integer.parseInt(eachStu[4]), Integer.parseInt(eachStu[5]),
Integer.parseInt(eachStu[6])));
}// End of while loop
}// End of try block

// Catch block to handle file not found exception
catch(FileNotFoundException fe)
{
System.out.println("\n ERROR: Unable to open the file for reading.");
}// End of catch block

// Close the file
readStuF.close();
}// End of method

 

I followed this code and for some reason its showing the error in the image. i cant figure out whats wrong, please help!

<terminated> Client (1) [Java Application] C:\Program Files\Java\jdk-16.0.1\bin\javaw.exe (28 Jul 2021, 8:39:54 pm – 8:39:54 pm)
ERROR: Unable to open the file for reading.
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.util.Scanner.close()" because "readStuF" is null
at Client.readStudents (Client.java:182)
at Client.main(Client.java:415)
Transcribed Image Text:<terminated> Client (1) [Java Application] C:\Program Files\Java\jdk-16.0.1\bin\javaw.exe (28 Jul 2021, 8:39:54 pm – 8:39:54 pm) ERROR: Unable to open the file for reading. Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.util.Scanner.close()" because "readStuF" is null at Client.readStudents (Client.java:182) at Client.main(Client.java:415)
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education