Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2013
    Location
    Wisconsin, USA
    Posts
    60
    Rep Power
    0

    Default problems solving 'Cannot Find Symbol'

    I'm working with a tutorial I found that shows how to use BufferedReader. I've already tried moving my readLines method inside the ending curly brace of my OpenFile method (in an attempt to make the numberOfLines variable not local to only the OpenFile method), but I' still getting red, so I'm back to square one. Here's the code of that class:

    package textfiles;

    import java.io.IOException;
    import java.io.FileReader;
    import java.io.BufferedReader;
    /**
    *
    * @author speterson86
    */
    public class ReadFile {

    private String path;

    //Constructor:
    public ReadFile(String file_path){
    path = file_path;
    }

    public String[] OpenFile() throws IOException{

    FileReader fr = new FileReader(path);

    BufferedReader textReader = new BufferedReader(fr);
    int numberOfLines = readLines();
    String[]textData = new String[numberOfLines];//sets up a String array.
    //The number of positions in the array (its size) is set to the number
    //of lines. We've put this between the square brackets.

    /*
    * To put all the lines of text from the file into each position in the
    * array, we need a loop. The loop will get each line of text and place
    * each line into the array:
    */
    int i;

    for(i=0; i < numberOfLines; i++){

    //Access the lines of text and store them in the array:
    textData[i] = textReader.readLine();

    }
    textReader.close();

    return textData;

    }

    //Add a new method called readLines to go through text file and count how
    //many lines it has:
    int readLines() throws IOException{
    //Set up another FileReader, and another BufferedReader:
    FileReader file_to_read = new FileReader(path);
    BufferedReader bf = new BufferedReader(file_to_read);

    //Read each line of text until there are no more lines of text, then
    //stop and return a value of null:
    while((aLine = bf.readLine()) != null){ ////aLine is underlined red
    numberOfLines++;//increment a counter called numberOfLines ////number of lines is underlined red
    }
    bf.close();
    return numberOfLines;
    }
    }

    Why are ////'aLine' and ////'numberOfLines' getting red inside of the readLines method?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: problems solving 'Cannot Find Symbol'

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,411
    Rep Power
    5

    Default Re: problems solving 'Cannot Find Symbol'

    alines and numberOfLines aren't declared anywhere within the method.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Problems with code/cannot find symbol
    By VIhuri in forum New To Java
    Replies: 4
    Last Post: 11-12-2012, 05:52 PM
  2. Can not find symbol ???
    By AliceNewbie in forum New To Java
    Replies: 1
    Last Post: 02-17-2010, 01:44 AM
  3. Replies: 9
    Last Post: 10-18-2008, 08:26 PM
  4. Replies: 3
    Last Post: 05-01-2008, 08:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •