I am getting an error that says "Exception in thread "main" java.util.NoSuchElementException: No line found" in Java. I have tried adjusting the lines that are available in the txt file, however, that doesn't solve the issue. The txt file has 20 lines: Nickle Patterson Senior CPSC 8 Tom Smith Sophomore EDUC 3 Mcfloos Loss Freshman CPSC 1 Charlotte Niematode Junior MATH 6 Sally Hampton Senior Psychology 7 Trying to get it to properly run. Any help is appreciated. Thanks

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

I am getting an error that says "Exception in thread "main" java.util.NoSuchElementException: No line found" in Java. I have tried adjusting the lines that are available in the txt file, however, that doesn't solve the issue. The txt file has 20 lines:

Nickle Patterson
Senior
CPSC
8
Tom Smith
Sophomore
EDUC
3
Mcfloos Loss
Freshman
CPSC
1
Charlotte Niematode
Junior
MATH
6
Sally Hampton
Senior
Psychology
7

 

Trying to get it to properly run. Any help is appreciated. Thanks

1® import java.io.*;0
3
4
5 public class Driver2
6 {
private static Student [] students = new Student[100];
private static Scanner kbd = new Scanner (System. in);
8
9
10
@SuppressWarnings("resource")
public static void main(String[] args) throws FileNotFoundException
{
110
12
13
14
FileReader file = new FileReader("students.txt");
Scanner in = new Scanner(file);
15
16
17
18
int i = 0;
19
while (in.hasNextLine())
{
String 11 = in.nextLine();
String 12 = in.nextLine();
String 13 = in.nextLine();
int sem = in.nextInt();
in.nextLine();
20
21
22
23
24
25
26
27
students[i++] = new Student(11, 12, 13, sem);
}
28
29
30
31
runMenu();
32
33
System.out.printf("Program Finished");
R Problems @ Javadoc E Declaration e Console X
<terminated> Driver2 [Java Application] C:\Users\desir\,p2\pool\plugins\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.1.v20211116-1657\jre\
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.base/java.util.Scanner.nextLine(Scanner.java:1651)
at Driver2.main(Driver2.java:26)
Transcribed Image Text:1® import java.io.*;0 3 4 5 public class Driver2 6 { private static Student [] students = new Student[100]; private static Scanner kbd = new Scanner (System. in); 8 9 10 @SuppressWarnings("resource") public static void main(String[] args) throws FileNotFoundException { 110 12 13 14 FileReader file = new FileReader("students.txt"); Scanner in = new Scanner(file); 15 16 17 18 int i = 0; 19 while (in.hasNextLine()) { String 11 = in.nextLine(); String 12 = in.nextLine(); String 13 = in.nextLine(); int sem = in.nextInt(); in.nextLine(); 20 21 22 23 24 25 26 27 students[i++] = new Student(11, 12, 13, sem); } 28 29 30 31 runMenu(); 32 33 System.out.printf("Program Finished"); R Problems @ Javadoc E Declaration e Console X <terminated> Driver2 [Java Application] C:\Users\desir\,p2\pool\plugins\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.1.v20211116-1657\jre\ Exception in thread "main" java.util.NoSuchElementException: No line found at java.base/java.util.Scanner.nextLine(Scanner.java:1651) at Driver2.main(Driver2.java:26)
1
2 public class Student
3 {
private String name;
private String status;
private String major;
private int sem;
4
7
8
10
11
12
public Student(String name, String status, String major, int sem)
{
this.name = name;
this.status = status;
this.major = major;
13
14
15
16
170
18
this.sem = sem;
}
public String getName ()
{
19
return name;
20
}
21
220
public String tostring()
{
return name + "\n" + status + "\n" + major + "\n" + sem;
}
23
24
25
26
27
28 }
29
Transcribed Image Text:1 2 public class Student 3 { private String name; private String status; private String major; private int sem; 4 7 8 10 11 12 public Student(String name, String status, String major, int sem) { this.name = name; this.status = status; this.major = major; 13 14 15 16 170 18 this.sem = sem; } public String getName () { 19 return name; 20 } 21 220 public String tostring() { return name + "\n" + status + "\n" + major + "\n" + sem; } 23 24 25 26 27 28 } 29
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Avoiding deadlock
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
  • SEE MORE 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