Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Invoking Method Returns 0

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a working test class, but the JFrame class JTextArea displays 0. Basically I upload a .txt file and my method counts the total of words for it. The JDialog box appears and I select the .txt file, but the Words Count display is always 0. I am assuming I need a while loop... but it always crashes the GUI application lol. I have the buttons and addActionListeners setup. I just need the Action Performed event handler to display the Words Count part. Thank you for helping me out!
-------------------------------------------------------------------

 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We can't see the code for FrameAnalyzer, but the first thing that leaps out is that you don't appear to do anything with the file you select, other than display its name. You don't read the file anywhere. And FrameAnalyzer.getWordCount() doesn't seem to have any way to tell what it's counting.
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How big is the txt file?

You should put the reading file part in a Callable (able to get the result back) to prevent the GUI to block/hang.
 
Abu Apu
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

K. Tsang wrote:How big is the txt file?

You should put the reading file part in a Callable (able to get the result back) to prevent the GUI to block/hang.



The txt file has around 12,000 words :P
 
Abu Apu
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Brown wrote:We can't see the code for FrameAnalyzer, but the first thing that leaps out is that you don't appear to do anything with the file you select, other than display its name. You don't read the file anywhere. And FrameAnalyzer.getWordCount() doesn't seem to have any way to tell what it's counting.



Hmmmmmm interesting. If the file is being selected why isn't it being read anywhere?
 
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Here FrameAnalyzer is an instance variable (please use lowercase for the first letter) but we don't know what type it is, so we don't know what getWordCount() does. If the class is one you wrote, could you post the code of that method? Also, how does FrameAnalyzer get the name of the file?
 
Abu Apu
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:
Here FrameAnalyzer is an instance variable (please use lowercase for the first letter) but we don't know what type it is, so we don't know what getWordCount() does. If the class is one you wrote, could you post the code of that method? Also, how does FrameAnalyzer get the name of the file?





FrameAnalyzer is type TextA_1
 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah in your getWordCount method, the map words is empty when you instantiate it.

You have a analyzeText method that looks like reading the file and populating the map words. Yet you didn't call this method.

Steps are:
1. instantiate FrameAnalyzer variable
2. call analyzeText method
3. call getWordCount method


After this you should get a non-zero value.

By the way in the analzeText method, FileNotFoundException is a subclass of IOException. Just a thought, is Scanner a good choice for reading files?
 
Abu Apu
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

K. Tsang wrote:Ah in your getWordCount method, the map words is empty when you instantiate it.

You have a analyzeText method that looks like reading the file and populating the map words. Yet you didn't call this method.

Steps are:
1. instantiate FrameAnalyzer variable
2. call analyzeText method
3. call getWordCount method


After this you should get a non-zero value.

By the way in the analzeText method, FileNotFoundException is a subclass of IOException. Just a thought, is Scanner a good choice for reading files?



Aw okay. I noticed I was never calling method from TextA_1 -____________- Also were not implemented correctly in their respectful places.

Anyways, it is working now !!! Boooooooooooooyah!!! Thanks for the help guys!
reply
    Bookmark Topic Watch Topic
  • New Topic