Keyboard input makes program hang

Hi,
I'm writing a small web service client that takes 2 numbers, sends them to the service and gets the sum/division/product/substraction back as an answer.
I'm finished with the C/S programming and all I want to do is for the user to input the numbers himself. I wrote the following lines, which should work just fine but for some reason the program hangs and when I type sthg, there's no input. Does anyone have an idea why?
private static float getNum() throws IOException
     float a;
     String message;
     BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in));
     System.out.println("Enter a number (float): ");
     message = stdin.readLine();
     // the following line is never reached.
     System.out.println ("You entered: \"" + message + "\"");
     a = Float.parseFloat(message);
     return a;
}Thanks.

something else must be swallowing System.in ??
how exactly are you running it?
an Ant task still has access to System.in from my tests eg
1)<?xml version="1.0" encoding="ISO-8859-1"?>
<project default="all">
    <target name="all">
        <taskdef name="TestInput" classname="TestTask"/>
        <TestInput/>
    </target>
</project>2)import java.io.*;
import java.util.*;
public class TestTask {
     public void execute() {
          try {
               BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
               List result = new ArrayList();
               for(String line=""; ((line=br.readLine())!=null) && !line.trim().equalsIgnoreCase("quit"); ) {
                    result.add(line);
               System.out.println("Got: "+result.size());
          } catch(Exception e) {
               e.printStackTrace();
     public static void main(String[]arg) throws Exception {
          new TestTask().execute();
}3) compile TestTask.java
4) save xml above as test.xml in same directory as the TestTask.class file
5) type "ant -buildfile test.xml"
everything works as expected..
you're not trying to access System.in via jsp or something??

Similar Messages

  • OptionPanes and keyboard inputs/exitting program (game quit)

    Hi there,
    Im implementing my game an assignment and Ive come across a problem that I cant seem to solve. Ive created an option pane that, in a win or lose situation, allows the user to restart or quit the game- the restarting is simple enough in that if the value of the option pane = 0 then it executes the resetGame method, the trouble comes with the quit option. At present it is linked to the resetGame but what I would really like is for it to have the same effect as pressing the 'S' key in the game (i.e. stop the game and display the main screen). Is there any way to do this? Is there like a quit to previous panel option, go back a screen, anything that can exit the game- as pressing s on the keyboard stops the game and goes back to the main screen.
    The code in question is;
    // make munchies move down the screen
    for (int i = 0; i < NUM_MUNCHIES; i++) {
    if (munchieDirection == 1){
    munchieYPos[i] = munchieYPos[i] + munchieSpeed;
    if (munchieYPos[i] > (boardHeight - munchieHeight)){   // if the munchies touch the bottom the create game end situation
    gameLoseSound.play();
    int value1 = JOptionPane.showOptionDialog(null, "Would you like to restart the game? If not, press Quit and type S to stop the game.", "You Lose", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, new Object[]{"Restart", "Quit"}, "Restart");
    if (value1 == 0){
    resetGame();} else {
    resetGame();} //change to quit value
    AND
    // scoring and reset
    if (score >= 5){
    gameWinSound.play();
    value = JOptionPane.showOptionDialog(null, "Would you like to restart the game? If not, press Quit and type S to stop the game.", "You Win", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, new Object[]{"Restart", "Quit"}, "Restart");
    if (value == 0){
    resetGame();} else {
    resetGame();} //change to quit value
    Any help on this matter would be much appreciated, as although my current method may suffice- its not 100% appropriate (in my opinion)

    Got my main account working again now!
    Still having trouble for this. Ive now completed the game- its all working, but I still havent solved the quit problem.
    Is there anyway I can have the mouse click of the 'quit' button to flag up the same command as pressing the s key on the keyboard? Or is it possible to allow the quit button to allow the user to exit to the main menu?
    PLEASE HELP! IM DESPERATE!
    Thanx
    Senor-cojones

  • [Solved] Programs hang on keyboard input (uim-xim)

    Update: I've narrowed the issue down (via trial and error) to uim-xim.  If it's running, it causes this problem (in XMonad) and if it isn't, gnucash has no issues.  Oddly enough, when I start uim-xim by hand after gnucash, it works fine too.  Starting uim-xim by hand before gnucash results in the same issue, and so I'm inclined to believe it's either an issue with XIM implementation, or simply uim-xim.  Might also be a mixture of XMonad and uim-xim, as it works fine in Openbox.
    I've noticed lately that certain GTK programs (I'd list them, but I haven't paid close attention until today, where I was using gnucash) work fine until I try to input anything via the keyboard.  The moment I start typing (or, at the latest when I hit the shift key or backspace key) the program will hang (without any error message).  I originally assumed that this was an issue with the program - not my window manager.  However, I tried one of the problem programs (gnucash) in Openbox today, and it works just fine.  That leads me to assume it's caused by my configuration in some way.  I have absolutely no idea where to start debugging this issue. 
    A bit of information:
    I use UIM (in both openbox and XMonad with identical configurations), run a script for a Japanese date format in XMonad (piped to dzen), and load the same xmodmap file in both window managers.  Also, I start all my window managers using CDM (Console Display Manager), but in the case of XMonad I supply a bash script instead of the binary, in order to preload certain files.  Also, I use a german keyboard layout.
    <I removed the rest of this post because it was long and, ultimately, irrelevant>
    Last edited by lswest (2012-05-01 09:53:46)

    spectater wrote:
    Same situation, Confirmed here
    I'm having the same problem with my laptop after upgrading to  gnome 3 : 
      gnome-terminal  , gedit  can not accept  keyboard input , lower case letters, enter ,   backspace and so on ,   but  upper case letters are OK.
    files  can not be renamed with  nautilus , also the find function affected  in nautilus
    while other programs such as  xterm ,firefox  , pidgin  skype , thunar  leafpad  libreofficecan  ...and so on  work out of the box .
    lower case & upper case letters all are not accepted well in my case.

  • Solaris 10 8/07 Install hangs awaiting keyboard input

    I have a W2100z Java Workstation that I am trying to install S10 8/07 on. When it first powers up, I get the standard bios prompts and can hit F2/F8 to customize things as I wish.
    However, when I start the Solaris install from CD, after the OS installer is loaded, it first prompts for 1, 2, 3, 4, ... choices (1 being an interactive install). No amount of keyboard punching seemed to get it to make a choice. So after about 30 seconds or so, it times out and presumes interactive install.
    After a bit, it loads a text-based window to let me choose a language. Just move the cursor around, select a language, and then hit F2 to continue. Unfortunately, it does not recognize any keyboard input and just sits there comatose for as long as I choose to wait.
    So, perhaps I have a keyboard issue, so I swapped out a Kensington for a Dell keyboard. That didn't work so I acquired a Sun keyboard. That doesn't work either. I've also plugged the keyboard into every USB slot I could find (two on the front and 3 on the back), all to no avail.
    Now, Solaris 11 from the SXDE has no problem booting and installing on this computer with all of those keyboards. Unfortunately, that is academic in that I need to run S10.
    So what is the magic to getting the W2100z to boot/install Solaris 10?

    After much gnashing of teeth and pulling of hair, I found an BIOS upgrade for the W2100z. The keyboard now is recognized and the bits are installing.

  • Can java program simulate keyboard input?

    is it possible to create a java program or applet that simulates an end-user's keyboard input into another java applet? is it also possible to feed the output of that target applet to a file based on the different input combinations?
    and How?
    Thanks.

    Take a look at the API-docs for the class java.awt.Robot . This generates system-level input-events. Might not work in an applet, I do not know whether an applet has the right to do this.
    The second question is actually the more difficult one, since normal applets can not do file access.

  • Reader Closes on any Keyboard input

    Has anyone had this problem?
    Reader closes on any keyboard input.
    Mouse works fine.  And I mean any keyboard action at anytime.
    I have tried uninstalling all adobe reader apps/plugins and reinstalling the latest available version but still Reader closes with any keyboard input.   Make opening password protected PDF's impossible.  The "find" function unusable.
    Any Ideas?

    Are you trying to run your application through TextPad, or some IDE? The System.in is best for command prompt input. Trying running your program through the command prompt, and it should work fine.
    I replicated your error, running your application through TextPad.

  • Lag keyboard input

    Hi, I have an issue with my first LabView program can anyone help me please?
    The function of my program is to manualy or automaticaly save the data obtained with the multimeter
    My program worked fine until I wanted to add a file creation function each time the program runs, but the program creates a file every 5 seconds, I have tried using a loop and case but I cant make it work, it still creates a file every 5 seconds.
    Any tips?
    Aditionaly I have tried to program a keyboard input for the buttons in the vi using a few examples I found around the forum but my program just lags and I cant even start measuring.
    I atach my vi for inspection , thanks in advance
    Attachments:
    maybe.vi ‏32 KB

    It probably shouldn't damage anythin constantly updating the loop, although it does introduce overhead and is generally not tidy, to avoid the constant updating I would recommend looking into shift-registers or feedback nodes. On that note, I'll leave you with this snippet, I'm sure you can see how it might apply.
    [Side-note; In case you don't know how to use a snippet, download and save the image, then drag the file from your explorer into a block diagram.]
    Attachments:
    Feedback Node.png ‏19 KB

  • Keyboard input for a nubie!!!!

    Can anyone help me with writng a method that accepts all keyboard input and writes it to a file? I.e. whenever a key is pressed (only letters and numbers), it is accepted even if no programs are running and no text editor is being used.
    This will help me great deal and I would be very appreciative for any help I might receive.
    Thanking any response
    ChaosSupreme

    Is this like making a key logger? It takes down all your input and saves it to a file? If it is I'm sure there are plenty of tutorials on how to make a key logger out there.
    I guess you would have to look up buffered writer and rile writer methods, although I think they are just through a text editor or program.
    Andy

  • Keyboard input stops after a few characters

    Suddenly, I cannot use Firefox 8.0.1. Keyboard input fails after a few characters. Sometimes (but not always), mouse input fails as well. The only button that works when this happens is the "X" (close program) button in the top right corner of the window.
    The only things I changed recently were adding FlashGot and Windows Media Player plugins. Firefox worked after each installation and continued to work for at least a couple of days.
    Did a complete removal including personal settings, clean installed 8.0.1 without any personal settings, but the problem persists.
    I have no other keyboard or mouse input problems with any other browser or programme. (I am submitting this on Chrome browser, and everything is fine.)

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode
    *https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes

  • Keyboard input through swing

    How do I make it so that in swing a person can press a keyboard button and it will then go to a new screen with out the unput dearea being visable. I tried doing it with a text area but when I made it invisible it would not respond to keyboard input?

    hi buddy,
    u can create a new JFrame and call tht in the text area's ActionListener
    and then while creating the JFrame use the Following code to close the frame on exit,
    ur swing program will surely respond to it then
    JFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    in case u want to get the text b4 closing u can use a string variable to set the text to it and then come out,
    cheers,
    hayath

  • When I plug my headphones into the headphone/optical out jack programs hang

    I have an iMac 20 inch LCD. On the back their is a jack with a picture of headphones, but it is also labeled as "optical out". I plug my headphones in and they work. Great. That is not my problem today.
    My problem is that whenever I plug the headphones in or unplug them, iTunes (and other apps using audio) hangs and when I try to adjust the volume with the keyboard buttons nothing happens for 15 seconds or more and then the volume changes, not that anything is able to play. If I wait for a minute or so then all my applications start working fine again and I am able to hear my music and adjust the volume.
    What in the world is going on?
    1.8 Ghz G5 1.25GB RAM   Mac OS X (10.3.9)  

    Thank you. That is good information.
    Does this mean that there is nothing I can do about the delay? When I think of a delay, I think of maybe 10 seconds. I am having to wait for a minute or more for my audio to switch. While I wait, I have no audio and any audio program hangs. Is there a setting I can change? It seems rather ridiculous that I have to wait so long just to switch from internal speakers to headphones.
    It is like this on other Mac machines? Or it is just my iMac? I hate to compare Mac to Windows, but on Windows or Linux computers the switch is instantaneous.

  • Problem with program hanging randomly on certain commands from win 7 pro client to SB Server

    Having a problem with program hanging randomly on certain commands from Win-7 Pro Client to SB Server Both 64-Bit
    Five other slower XP-Pro 32 Bit systems though they are older and slower systems do not seem to hang as readily if at all.
    It has been very frustrating as the Client-System, SB-Server and Program should work w/o any hitches, but this seems to work fine @ times and then hang randomly.
    Would appreciate any and all suggestions in assisting.... JimBAgde-MSS  

    You can try this, as I have had similar problems with another MS Access .MDB file and slow access before. This fixed my problem for me. On the slow computer, make sure the program is set to see the .mdb file via UNC path, not a mapped drive letter. ex.
    USE:  \\yourserver\shared\dental\file.mdb
    DO NOT: S:\\shared\dental\file.mdb
    hope this helps

  • How to use the phone's Mini-Keyboard Input with the 'Textbox'(MIDP2.0)?

    (My apology. My English is not perfect but I'll try my best. >_<)
    Hi. I'm trying to create a textbox(in my own little application) that is compatible with the mini-keyboard input feature.
    This problem involved any device that have a built-in "mini-keyboard".
    Problem:
    I tried the 'Textbox' class from MIDP2.0 but the result, as expected, is like using the phones with no built-in keyboard.
    (Forexample if I want to input the character 'C' inthe text box, I need to press number '2' button three times to let it circle through 'A' -> 'B' then 'C'. )
    Then I tried entering URLs in the phone's built-in web browser, the result is I can use the mini keyboard to type like a PC keyboard.
    Question: How do I implement such textbox that is fully compatible with the built-in mini Keyboard?
    I tried browsing through the MIDP2.0 API but it seems the 'Textbox' class there couldn't do it.
    Thank you. =)
    /bow
    Edit/Delete Message

    The textbox should have input just as any other normal phone input. If not, something strange is going on.
    Anyway , there is no use to make your own input method, since every phone has another implementation of this anyway. It would only confuse users.

  • Firefox and Thunderbird are suddenly not accepting keyboard input

    Keyboard shortcuts still work just input in any kind of input field fails so I can still use ctrl+C / CTRL+V to somewhat use firefox and Thunderbird But all input fields are completely unresponsive to keyboard input
    The problem suddenly arose while I was browsing.
    I have the same issue on all program's based on the Gecko engine and I confirmed them so far in Firefox, waterfox, instantbird, thunderbird and fossamail. However chromium / windows / basically everythign n
    To fix it I tried the following:
    Restarting firefox
    Restarting firefox in savemode
    Rebooting
    Changing the keyboard layout in windows
    Using a different keyboard
    Again rebooting
    Pressing F7 to check for caret mode which was disabled
    pressing winkey + F9 (Whatever that does)
    I am running windows 8.1(x64)

    Solved, Changing the keyboard layout again and rebooting fixed it. I tried using the on screen keyboard which worked so I changed the keyboard layout again and rebooted and now it works just fine. I still wonder what caused a Gecko wide issue like this?

  • Spaces locks keyboard input

    Per Sean Dale1, the following was mis-posted in the 10.5 Leopard thread (original post here: http://discussions.apple.com/thread.jspa?threadID=2201088):
    Have been running into this problem more and more frequently on both a MacBook Pro and Mac Pro tower running 10.6.1 and 10.6.2: when I Control-right-arrow to move to my other "space" one or two of two bad things will happen:
    (1) the icon in the middle-bottom of the screen showing which "space" I'm in does NOT fade away and disappear
    (2) I am prevented from doing ANY keyboard-input into my programs there. I will be able to click and highlight windows using the mouse, as well as see menus activating and such, but anywhere there is a text field (browser or address book or ANYwhere) keyboard input is not displayed.
    The only solution is to go into the Activity Monitor and quit the Dock application.
    Have been seeing this problem for a few weeks which persists through reboots and such.
    Ideas?

    This issue is being covered in more detail at this thread:
    http://discussions.apple.com/thread.jspa?threadID=2161076
    This suddenly started happening to me yesterday and now happens every time I switch Spaces with the keyboard. I've found that the only way around it is to only use the menubar icon to switch. Because I'm so used to clicking keys to switch Spaces and still do it unconsciously, I've disabled the keys in Spaces prefs.

Maybe you are looking for

  • The software Sticky Password Doesn't work.

    the plugin Sticky Password doesn't work in Firefox 37.

  • Image Displays Differently in PS and Br CS4

    I have a gs tif file that I converted to cmyk. In PS the cmyk version looks virtually identical on screen to the gs version although when you hold the eyedropper over the image, cyan displays as a higher percentage than m or y, with k lowest in both

  • Correct JNI_OnLoad JNI_OnUnLoad approach for cacheing jvm ref?

    Currently am successful in calling a C API from Java. What am basically trying to do here is catch an event in C program, and callback the Java instance, to handle it in my Java code (Similar to a event handling in Swing). I have implemented the even

  • Conversation view like mail in lion

    Hi! I am not able to see the mails in the usefull conversation view I have in Lion when the messages are orgnised in thread. It's seems that ios5 organized the similar messages in thread and when u click on it it shows the mails separated each other

  • Crashing U410 errors warning

    Hi, Bought a brand new Lenovo U410 a month ago. Thing worked like a charm for like half a day. Got a few problems with this lovely peace of sh*t.  First of all the touchpad. Works fine until you decide to use one of the Office programs. Whole thing l