Hey guys and girls, first post here been reading for a few days but I am pretty new to java and I have to edit a class to import a file into an array. The class initially defined the array within itself. So I made my changes and I am getting a symbol not found on lines 75 and 82, in reference to inFile object of the Scanner class. Any help would be greatly appreciated, especially format criticism as I would like my future programs to be readable.

//package ChargeAccount;
import java.util.*;
import java.util.Scanner;
import java.io.*;
public class ChargeAccount {

    private int search;
    private String fileName;
    private int indexPos;
    private boolean check;
    private int sizeCount;
    private boolean fileExist;

    private int[] accounts; //modify the original array into a non final
    /*= { 
    5658845, 4520125, 7895122, 8777541, 8451277, 1302850,
    8080152, 4562555, 5552012, 5050552, 7825877, 1250255, 
    1005231, 6545231, 3852085, 7576651, 7881200, 4851002 };*/

    public ChargeAccount(){ //no arg constructor, sets search to -1 and sends toresults method
    search = 0;

    public ChargeAccount(int search, String fileName){
    //I need to define a public array here dependant on a file identified by user
    this.fileName = fileName;
    Scanner keyboard = new Scanner(System.in);

    //Used for debugging System.out.println(""+accounts.length);
    this.search = search;
    check = returnResults(search);
        System.out.println("The account "+search+" was not found");
        else {
        System.out.println("The account "+search+" was found at position: "+indexPos);

    private boolean returnResults(int search){
    if(search == 0){
        return false;
    else {
        indexPos = Arrays.binarySearch(accounts, search);
            if(indexPos != -1)
        return true;
            return false;

    //create a method that does the file validation and array creation fileToArray()
    public void fileToArray(String fileName)throws IOException{
    this.fileName = fileName;
    Scanner keyboard = new Scanner(System.in);
    //first i need to identify how many elements will be in the file
    //ill use a do while with nested if/else
        File file = new File(fileName);
        fileExist = false;
        System.out.println("File "+fileName+" does not exist, please enter a different file name with extension(*.txt)");
        //Consume the next line into fileName
        fileName = keyboard.nextLine();
        Scanner inFile = new Scanner(file);
        fileExist = true;
        //Now that we have a validated file, lets find how many elements are within
        //ill use a while to determine this
        //now we've obtained the sizeCount, we'll use that to initialize the account array
        accounts = new int[sizeCount];
        //thats done, lets add our elements
        for(int i = 0; i < sizeCount; i++){
        accounts[i] = inFile.nextInt();



5 Years
Discussion Span
Last Post by Lamirp

Make sure the definition of the inFile variable is in scope where you are trying to use it.
In scope means defined within the same pair of {}s where it is being referenced.


Thank you NormR1, I was assuming while in the scope of the method I would be okay. Glad to get that one out of the way.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.