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

Command line question

Kev Woo
Greenhorn

Joined: Nov 03, 2010
Posts: 11
I'm writing a program for a 3D tic-tac-toe game and it requires two things:

1. The program must be able to display the board with a set of predetermined positioning and values from a file given from the command line.
2. Requires interactive play if there is no file given.

I have the code for each part, they both compile and run fine, however, I need to include them in the same program.

If I try to run the program without giving the file name through the command line, I get the OutOfBounds error which prevents me from using the interactive portion.

Is there a way to run the program and bypass the command line code if there is none entered?

Thank in advanced, let me know if you need to see the actual code or need more clarification.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3837

If I try to run the program without giving the file name through the command line, I get the OutOfBounds error which prevents me from using the interactive portion.

That particular program may expect an argument to the Java command. You might need to consider the both programs and come up with a logic to handle the issue for the merged one. You may post the portions of each program related to this issue so that others can be more helpful.

SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Kurt Van Etten
Ranch Hand

Joined: Sep 07, 2010
Posts: 98
Kev Woo wrote:If I try to run the program without giving the file name through the command line, I get the OutOfBounds error which prevents me from using the interactive portion.


I'm assuming this happens when your program tries to access the variable args[0], which doesn't exist if no command line arguments were supplied when the program was invoked. All you need to do is check args.length first to see if any arguments are present. This is probably something your command-line version should do anyway, since dying with an array index out of bounds exception is a rather ungraceful way for a program to exit if the user forgets to type in the argument(s).
Kev Woo
Greenhorn

Joined: Nov 03, 2010
Posts: 11
Thank you very much, got it working
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Command line question