Page 1 of 1

Run Java Application works but not Run

Posted: Fri Jun 27, 2003 12:56 am
by garitt
I have the following in the CLASSPATH = .;
I am using Windows 2000
I have the directory structure as C:\Java\sample
All my programs are written under the directory sample.

This is the piece of code I am trying to RUN...

---------------------------

import java.io.*;

class HelloYou {
public static void main (String args[]) {
byte name[] = new byte[100];
int nr_read = 0;
System.out.println("What is your name?");
try {
nr_read = System.in.read(name);
if (nr_read!=0)
System.out.println("Value of nr_read - >"+nr_read);
System.out.print("Hello ");
System.out.write(name,0,nr_read);
}
catch (IOException e) {
System.err.println ("Error.");
}
}
}

--------------------------

This code compiles successfully. Now when I am trying to execute the command "Run Java Application", the DOS prompt opens up and after printing the intial stuff, waits for user prompt. And then program keeps flowing correctly.

However, if I execute the command "Run" a dialog box opens up having 3 fields.
1. Command -> C:\j2sdk1.4.1_03\bin\java.exe
2. Parameter -> HelloYou ABC
3. Initial Folder -> c:\Java\sample

This when executed, and output selected as Textpad, then control shifts to catch block and "Error" is printed out.

Can anyone explain why ?

Posted: Fri Jun 27, 2003 6:09 am
by MudGuard
Change your catch block to

Code: Select all

catch (IOException e) 
{
  System.err.println ("Error. " + e);
} 
Then you will see which Exception is thrown.
If that does not help you in finding the error, come back here.

And tell us
- what you enter
- what exactly is output[/code]

Re : Run Java Application works but not Run

Posted: Fri Jun 27, 2003 10:22 am
by garitt
This is the output ---

What is your name?
Error.java.io.IOException: The handle is invalid

Any suggestion ?

Posted: Fri Jun 27, 2003 11:22 am
by MudGuard
Are you running the Java program from Textpad?

Then look at http://www.textpad.com/forum/viewtopic. ... t=redirect

Capture Output unchecked

Posted: Fri Jun 27, 2003 5:38 pm
by garitt
Thanks for the reply. As was mentioned, I unchecked the "Capture output" option.

This resulted in opeing up the DOS window and all the results being displayed properly.

This is the same as executing the option "Run Java Application".

I was hoping to capture the output in Textpad window. That is why I was executing the command "RUN" and checking the option "Capture Output". But that does not seem to work.

Regards,
Arijit