This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Endless loop

 
Tim Barker
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Expert:
Below I have included a simple DO WHILE loop. Occasionally when I try to exit the loop it says batch file missing and re-enters the loop. I have the code from the main method as well as the output when the error occurs.

import corejava.*; //This is for the Console.read
class cyrptograph
{
public static void main (String args[])
{
char quit;
do
{
System.out.println ("Enter 1 to encode a message");
System.out.println ("Enter 2 to decode a message");
int resp = Console.readInt ("enter choice:");
if ( resp == 1)
encode();
else
decode();
String response = Console.readLine ("Enter C to continue or Q to quit");
quit = response.charAt(0);
} while (quit == 'C' | | quit == 'c');
System.out.println ("Goodbye");
} //end of main

This problem only happens periodically, but here is output I get when it happens:

Enter C to continue or Q to quit q
Goodbye
Batch file missing
C:\JavaPro\Practice\DosApp\Cryptography>
Enter 1 to encode a message
Enter 2 to decode a message
enter choice:

You can see how it prints "Goodbye" which means it has exited the DO WHILE loop, yet it somehow ends up back in the loop. Does anyone know why?

 
Chad McGowan
Ranch Hand
Posts: 265
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you invoke this program? Do you use java from the command prompt?
 
Tim Barker
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No I use TextPad, but I am sure I could find the same problem from the command prompt.
 
Metal Zhang
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error message "Batch file missing" is defined by yourself?
I think maybe you can convert your definition of 'char quit' to
'String quit',and do like this:
do{
........
String quit;
quit = response.subString(0,1);
........
}while(quit.equals("C") | | quit.equals("c"))
------------------
Java lover from hell!
 
Tim Barker
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That makes sense. I never defined "Batch file missing", but it is probably part of the Corejava that I imported. The Corejava is from the book of the same name that included a CD-ROM that allows you to input information with the Console.line command and probably took exception to how I used it. I can check the files to see if that is a exception that it throws.
Thanks
 
Chad McGowan
Ranch Hand
Posts: 265
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tim Barker:
No I use TextPad, but I am sure I could find the same problem from the command prompt.

Have you tried it from the command prompt? The reason I'm asking is to find out where this "batch file" error message is coming from.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic