Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7709819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:57:29+00:00 2026-06-01T00:57:29+00:00

I have a program that reads input from a file. I am trying to

  • 0

I have a program that reads input from a file. I am trying to delimit input to only return tokens after a comma. But it doesn’t seem to work. Here’s my code so far:

package usegradebook;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class GradeBook {

private static Object[][] studentRecords = new Object[8][8];

public void compileRecord() throws FileNotFoundException
{      

   File file = new File("SomeData.txt");                   
   Scanner input = new Scanner(file);
   input.useDelimiter(",");

   for(int row = 0; row < studentRecords.length; row++)
   {
       for(int column = 0; column < studentRecords[row].length; column++)
       {
           studentRecords[row][column] = input.next();                    
       } 

   }                
   input.close();
}

Here is the data:
LastName,FirstName,Exam1, Asg1, Asg2, Exam2, Asg3, Asg4
Karr, Arlen, 91, 86, 94, 100, 98, 93
Stotz, Ralph, 81,83,,93, 78
Yi, Yu, 99, 88, 101, 76, 90, 94
Rao, Sista, 91, 86, 94, 100, 98, 93
Christopher, Thomas, 78, 79, 82, 88, 78, 91
McClurg, Andrew, 91, 87, 99, 87,,93
Noble, Rich, 84, 79, 85, 88, 90, 91
Johnson, Mark, 100, 100, 100, 100, 100, 100

It returns a “Exception in thread “main” java.util.NoSuchElementException”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T00:57:30+00:00Added an answer on June 1, 2026 at 12:57 am

    The problem is with input. It is missing 1 data for one of the record. So when it comes to the last record’s last data you will end up calling input.next() when there is no data. Also make sure you check with hasNext() before you call next() on the scanner object, that will prevent you from this exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that reads data from a file line-by-line. I would like
I want to have a program that reads metadata from an MP3 file. My
I've got a program that reads and sorts information from a CSV file but
I have to write a program that read from a file that contains the
I have a program that loads a file (anywhere from 10MB to 5GB) a
I'm trying to give a file as input, have it changed within the program,
I've got a piece of an application that reads input sometimes from a file,
I'm trying to input data from an XML file in a C++ program using
Im writing a program that should read input via stdin, so I have the
I have a python program that reads floating point values using the following regular

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.