GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Question about Tree Node --Word Tree Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question about Tree Node --Word Tree" Watch "Question about Tree Node --Word Tree" New topic
Author

Question about Tree Node --Word Tree

Taylor Woods
Greenhorn

Joined: Mar 19, 2005
Posts: 10
Hello. I just learned basic stuffs about Tree Node, and I managed to fisnish my first simple program using Tree. Now, I'm challenging second tree program, and it's extremely hard for me...

The direction for this program is as shown below:


The book says that I need to use
%java WordTree"text.txt"count.txt to run this program.
--"text.txt" is the text file that the data is stored.

And...even though I did as the book showed, it keeps showing me errors
that say:



and


Could anyone show me how to fix those errors or show me another way to
creat this program?

Thank You for regarding my question.
And I will appreciate if anyone could give me some help.

Thank you. I hope you have a nice day.
[ March 28, 2005: Message edited by: Taylor Woods ]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18874
    
  40

I think you may have forgotten to block the "else" clause. Try:



Henry
[ March 28, 2005: Message edited by: Henry Wong ]

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
As well, Integer doesn't have a no-argument constructor.
Taylor Woods
Greenhorn

Joined: Mar 19, 2005
Posts: 10
Thank you, David and Henry!! After following you guys' instructions, it seems to work. However, there is one problem. For this code, I need to use specific text file and specific command...

What if I want to put the data in this main code istead of putting it in the specific text file so I don't have to use that specific command?

Could you tell me which part I'm supposed to change and how I'm supposed to change? I'm sorry that I'm bothering you too much. Thank you so much.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by Taylor Woods:
What if I want to put the data in this main code istead of putting it in the specific text file so I don't have to use that specific command?
I don't follow. You already have it such that the user can specify the input and output file names. Do you want them hard-coded into the class? If so, just define constants instead of using args[0] and args[1], but that's probably not what you mean.

And what command? The "java WordTree" command? You could create a batch file called wordtree.bat:
Taylor Woods
Greenhorn

Joined: Mar 19, 2005
Posts: 10

But...I don't know exactly how I should declare the String input in this code. And what do you mean by defining constants? Is it what I just asked you about? If so, how do I do it using args[0] and args[1]?

Since I don't quite understand this code, I hope you could show me exactly how the codes should be.

Oh...and last question~ if I'm going to specify the input file and use it to run the program, how do I run it? It seems to compile ok...but it shows this messayge:

WordTree.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Tool completed successfully

and it doesn't run if I use normal way to run this
which is:

c:\java\bin\java WordTree


If I run this using "c:\java\bin\java WordTree", it syas that

Usage: Word Tree inputfile & outputfile


How can I run this program properly?

Thank you so much for your consideration and help, David. I truly appreciate it.

[ March 29, 2005: Message edited by: Taylor Woods ]
[ March 29, 2005: Message edited by: Taylor Woods ]
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Taylor,
If u don't want to use the arguments in specifying ur input... You can just remove your if-condition check at the beginning of the program...

Instead of
String inputfile = args[0];
String outputfile = args[1];

Just use
String inputfile = textYouWant;
String outputfile = args[0];

But you still need to specify the output file when running your program... But you just need one arguments... Like the following...

java WordTree C:\MyOutputFile.txt

I hope this helps...


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question about Tree Node --Word Tree