Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Invoking Method Returns 0  RSS feed

 
Abu Apu
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!
-------------------------------------------------------------------

 
Matthew Brown
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.
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • 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?
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • 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
Firefox Browser Java Mac OS X
  • 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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!