Run Java Application works but not Run

Using the Java SDK with TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
garitt
Posts: 3
Joined: Thu Jun 26, 2003 10:28 pm

Run Java Application works but not Run

Post 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 ?
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post 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]
garitt
Posts: 3
Joined: Thu Jun 26, 2003 10:28 pm

Re : Run Java Application works but not Run

Post by garitt »

This is the output ---

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

Any suggestion ?
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post by MudGuard »

Are you running the Java program from Textpad?

Then look at http://www.textpad.com/forum/viewtopic. ... t=redirect
garitt
Posts: 3
Joined: Thu Jun 26, 2003 10:28 pm

Capture Output unchecked

Post 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
Post Reply