• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Invoking Method Returns 0

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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
  • 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
Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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: 7108
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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
Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
  • 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
  • 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!
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic