File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes StreamTokeniser Trouble Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "StreamTokeniser Trouble" Watch "StreamTokeniser Trouble" New topic
Author

StreamTokeniser Trouble

Rich Charlton
Greenhorn

Joined: Nov 11, 2004
Posts: 19
Hi all,

im trying to build a text classification program that reads in a text file, tokenises it and stores it in a hashmap. Along the way i would like to instantiate another class which reads a text file full of commonwords. I would then like to remove these common words from the initial hashmap. I have set up two classes one called CommonWords.java and the other called Train.java. I am getting an error which i have posted after my code.

Train.java

CommonWords.java

Error Message:

I think i have something wrong with the adding of the commonwords to the hashtable..

Does anyone have any ideas.

Thanks
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

cWords = new HashMap ();

is missing before usage.
Next time mark line 26, to make it more easy to find it.
Read the message.
Try to understand it yourself.
Use a tool which has linenumbers.
(Everything except Notepad has linenumbers).

Post such basic questions to beginners.


http://home.arcor.de/hirnstrom/bewerbung
Rich Charlton
Greenhorn

Joined: Nov 11, 2004
Posts: 19
thats great am able to get the items added in the commonwords class. although im still having a problem removing the items from the initial hashmap. i have changed it slightly now to use an arraylist for the commonwords instead of a hash table as i had no need for a value next to the string.

im not sure whether the remove statement is going to work now.
as counts is a hashmap and cwords is an arraylist of string objects.

so problems at the moment are that i cant instantiate the arraylist and cannot remove commonwords from hashmap.

any ideas thanks.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Printing a class doesn't mean implicitly print all members of the class, and especially not to print all elements in a collection.

You might overwrite toString () in CommonWords, to achieve this, where you have to iterate over the arraylist and print every element, or create a new method like 'printAllElements'.
Rich Charlton
Greenhorn

Joined: Nov 11, 2004
Posts: 19
Thanks for your help guys....

I have re written my program logic now...although i have another problem...
I have started a new thread in the intermediate java forum if you can spare a look.

Thanks
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Although this thread is a little old, I'd just like to point out that ArrayList already overrides the toString() method to print out all the elements it contains. In fact, most Collection classes do, afaik. This means you don't have to iterate over a Collection manually when you write a toString() method for your own class.

Layne


Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: StreamTokeniser Trouble