Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Command line question

 
Kev Woo
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kurt Van Etten
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much, got it working
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic