Hi,

I need some help with an assignment - to read from a .txt file and count paragraphs, lines, words and characters. I've managed to write a program to read the file, and another one to count - but I've run into problems trying to incorporate the two.

I've sent myself loopy trying to sort it out so would really appreciate help. I don't think I will ever be a threat to the programmers of the world but need to pass this module so I can concentrate on the things I am good at!

Getting 'cannot find symbol' errors on lines 31, 53 & 54

import java.io.*;
import java.util.*;

public class AnalyzerTwo
{
	
			
    	
public static void main(String[] args) //main method
	throws IOException
	{
	
        try {
			
			//File reader to read the file named in command line one character at a time 
			FileReader input = new FileReader(args[0]);
            
			//Filter FileReader through a Buffered read to read a line at a time 
			BufferedReader buffer = new BufferedReader(input);
			
            int paragraph = 1;	// Line number of count 
            boolean endfile = false;
		while (!endfile)
		{
			int characters = 0;
			int words = 0;
			int lines = 0;
			
			while (true) //loop
			{	
				String hold =  new hprintln(); //constuctor
				System.out.println ("");	
				
				
				String line; // String that holds line
				if (line == null)
				{
				endfile = true;
				break;
				}		
				StringTokenizer tokenizer = new StringTokenizer (line);
				if (!tokenizer.hasMoreTokens())	
				break;

				++lines;
				while (tokenizer.hasMoreTokens())
				{
				++words;
				tokenizer.nextToken();					
				}
				
				characters += line.length();
				hprintln("+" + line);
				hprintln("." + characters + "" + words + "" + ""+ lines);
			}
			
			if ( lines>0)
			{
				System.out.println
				( "Paragraph" + paragraph + "." +lines + "lines," 
				+ words + "words," + characters + "characters" );
				
				++ paragraph;
			}
            
            buffer.close();
			
		}			

		}catch (IOException e)
		{
			// If exception generated, print a stack trace
            e.printStackTrace();
		}
	}
}
        
   // end main

Recommended Answers

All 2 Replies

"Cannot find symbol" means you are using a class, method, or variable that hasn't been defined. In this case, you are calling "hprintln()", which doesn't exist in that file.

Thanks - I thought I had done that (about 10 time in different positions and with differing words) - but I'll try again!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.