Reading Java text files: 15 Error: Can not find a symbol

advertisements

Im trying to read the content from a text file. ReadTextFile.java and ReadTextFileTest.java are in the same package ReadTextFile. I am using 2 packages in one project, ReadTextFiles and CreateTextfiles. ReadTextFiles package reads content from a text file and CreateTextFile package inputs content into a text file.

When I get to the command prompt I try to compile the java file into a class file by javac ReadTextFileTest.java. I get the following error everytime.

  1. ReadTextFileTest.java:15 error: cannot find symbol
  2. ReadTextFile application = new ReadTextFile();
  3. ^
  4. symbol: class ReadTextFile
  5. location: class ReadTextFileTest
  6. ReadTextFileTest.java:15 error: cannot find symbol
  7. ReadTextFile application = new ReadTextFile();
  8. ^
  9. symbol: class ReadTextFile
  10. location: class ReadTextFileTest 11.2 errors

Im guessing its having trouble recognizing the object I created of the ReadTextFile.java class.

Here is the two classes I used: ReadTextFile.java

package ReadTextFile;

import java.io.File;
import java.io.FileNotFoundException;
import java.lang.IllegalStateException;
import java.util.NoSuchElementException;
import java.util.Scanner;

import AccountRecord.AccountRecord; 

public class ReadTextFile
{
    private Scanner input;

public void openFile()
{
    try
    {
        input = new Scanner( new File( "clients.txt" ) );
    }
    catch ( FileNotFoundException fileNotFoundException )
    {
        System.err.println( "Error opening file." );
        System.exit(1);
    }
}

public void readRecords()
{
    AccountRecord record = new AccountRecord();

    System.out.printf( "%-10s%-12s%-12s%10s\n", "Account",
            "First Name", "Last Name", "Balance" );

    try
    {
        while ( input.hasNext() )
        {
            record.setAccount( input.nextInt() );
            record.setFirstName( input.next() );
            record.setLastName( input.next() );
            record.setBalance( input.nextDouble() );

            System.out.printf( "%-10d%-12s%-12s%10.2f\n",
                    record.getAccount(), record.getFirstName(),
                    record.getLastName(), record.getBalance() );
        }
    }
    catch ( NoSuchElementException elementException )
    {
        System.err.println( "File improperly formed." );
        input.close();
        System.exit( 1 );
    }
    catch ( IlegalStateException stateException )
    {
        System.err.println( "Error opening file." );
        System.exit( 1 );
    }
}

public void closeFile()
{
    if ( input !=null )
        input.close();
}
}

ReadTextFileTest.java

package ReadTextFile;

public class ReadTextFileTest
{
    public static void main(String[] args)
    {
    ReadTextFile application = new ReadTextFile();

    application.openFile();
    application.readRecords();
    application.closeFile();
    }
}


Add import statement as below:-

package ReadTextFile;

import ReadTextFile;

public class ReadTextFileTest
{
    public static void main(String[] args)
    {
    ReadTextFile application = new ReadTextFile();

    application.openFile();
    application.readRecords();
    application.closeFile();
    }
}