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
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
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)](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe47c4bd6-568c-4770-a86e-93574933d968%2F2153c410-b401-4c14-8bcb-c17a3b604f09%2F3kv8wc_processed.png&w=3840&q=75)
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)

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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images

Knowledge Booster
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.Recommended textbooks for you

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education