Results 1 to 3 of 3
  1. #1
    SamJava_the_Hut is offline Senior Member
    Join Date
    Jul 2013
    Wisconsin, USA
    Rep Power

    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;

    * @author speterson86
    public class ReadFile {

    private String path;

    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();


    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
    return numberOfLines;

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

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    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 offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default Re: problems solving 'Cannot Find Symbol'

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

    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on 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