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 8634009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:36:40+00:00 2026-06-12T09:36:40+00:00

I have a function that reads through a file, and gathers the results into

  • 0

I have a function that reads through a file, and gathers the results into an array list.
The array list looks like this (data)

[12, adam, 1993, 1234, bob, 1992]

I then need to load these details into new objects called patients. This is the current method I have so far for putting each separate array list item into its own patient, yet it keeps bugging me with an error saying I am passing in String String Int, and it needs to be a String.

s looks like this

12, adam, 1993

And this is the code

public void loadPatients()throws Exception
{
    ArrayList<String> data = IO_Support.readData("PatientData.txt");

    System.out.println(data);
    for(String s : data)
    {
        Sytem.out.println(s);
        patientList.add(new Patient(s));
    } 
}

Is there a way to push my array list result into a string for passing into the patient object, or should I use a different way to split the string results?

Read data looks like this

public static ArrayList<String> readData(String fileName) throws Exception
{
    ArrayList<String> data = new ArrayList<String>();
    BufferedReader in = new BufferedReader(new FileReader(fileName));

    String temp = in.readLine(); 
    while (temp != null)
    {
        data.add(temp);
        temp = in.readLine();   
    }
    in.close();
    return data;
}
  • 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-12T09:36:41+00:00Added an answer on June 12, 2026 at 9:36 am
    while (temp != null)
    {
        temp = in.readLine();   
    }
    

    First thing, You are never adding your input to the ArrayList.. This while loop makes no sense.. It is just reading user input, and swallowing it on every occassion..

    Plus, after seeing your exception, its sure that you are using a 1-arg constructor of Patient class which is not there.. There are only 0-arg constructor and 2-arg constructor in Patient class.. You need to use them indeed.

    See this code in loadPatient method.. You need to add a 1-arg constructor in your Patient class to get it compiled..

    patientList.add(**new Patient(s)**); --> Will not work
    

    So, in your Patient class, add: –

    public Patient(String s) {
        this.s = s;
    }
    

    this.s is the instance variable to store s that you passed..

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

Sidebar

Related Questions

I have a function that reads a formatted file. It looks like this: 1;Name_of_the_author;The
I have this function on my controller (Im using CodeIgniter) that reads the database,
I have a function that is supposed to read from a file into a
I have a function that reads a text file containing two lines, it reads
I have a C function that reads a stream of characters from a FILE*
I have this function that iterates through a directory and is supposed to read
I have an example function below that reads in a date as a string
I have a function, that reads a registry key, get a path for a
I want to write a function that reads a file and counts the number
I have a function that allocated a buffer for the size of a file

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.