Please Help in Buffered Reader getting error.....

Getting error
java.lang.NumberFormatException: For input string: ""
     at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
     at java.lang.Integer.parseInt(Integer.java:468)
     at java.lang.Integer.parseInt(Integer.java:497)
     at charread.main(charread.java:18)
    import java.io.*;
    class charread
        InputStreamReader ir=new InputStreamReader(System.in);
        BufferedReader br=new BufferedReader(ir);
        public void main()throws IOException
            InputStreamReader ir=new InputStreamReader(System.in);
            BufferedReader br=new BufferedReader(ir);
            System.out.println("enter a character");
            char p=(char)(br.read());
            System.out.println("entered character = "+p);
            System.out.flush();
            System.out.println("enter a number");
            String s=br.readLine();
            int n=Integer.parseInt(s);
            System.out.println("enter a number = "+n);
        Please Help.....

JoachimSauer wrote:
First you read a single character, then you read the rest of the line.
You probably entered a character and pressed enter.
read() returned the character, readLine() returned the rest of the line, which is an empty String. And empty String can't be converted to an int.
It's probably the easiest approach to just replace read() with a readLine() and take the first character of that String (after verifying that there is a character and optionally that there's only one character in that String).Alternatively you can call readLine() after you read the char.
However this is merely a quick fix and I am concerned about other aspects of your program.
InputStreamReader ir=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ir);The alternative to wrapping a BufferedReader around an InputStream is to use a Scanner, contrast the above example with the one below:
Scanner sin = new Scanner(System.in);
System.out.flush();Calling flush in this situation in unnecessary.
int n=Integer.parseInt(s);Place the following code in a try/catch block every single time you parse a String from a user into an Integer in case an Exception occurs, e.g. user enters a word or letter.
Integer n = null;
while(n == null) {
  try {
    String s = br.readLine();
    n = Integer.parseInt(s);
  } catch(NumberFormatException e) {
    System.out.println("Please enter an Integer");
}Finally onto Class naming conventions, Class names begin with a capital letter, variables and methods begin with a lower case letter.
class charreadAvoid naming methods "void", especially with a return value of null. Or one might think, well in my case anyway that this is the entry point into your application.
public void main()Mel

Similar Messages

  • PLEASE HELP !!! Getting error ORA-02438 and ORA-00910

    Hi,
    I am trying to create a table, have a field "Financial_Aid_Requested" declared as CHAR() and has a check constraint on it, when I try to run it, it gives me error "ORA-00910: specified length too long for its datatype" and so when I try to change the datatype to VARCHAR2 or even CHAR(2000), or CHAR(2) it gives me error "ORA-02438: Column check constraint cannot reference other columns"
    PLEASE HELP, I AM STUCK WITH THIS THING !!
    Below is What I have written as a part of query :
    Financial_Aid_Requested      CHAR() NULL
    CONSTRAINT CK3APPLICATION_INFO
    CHECK (Financial_Aid_Requested IN (Y,N))
    Thank you in advance.

    I wonder why you use CHAR in the first place, why not VARCHAR2(1)?
    You have to put Y and N between quotes:
    create table mytab (
    Financial_Aid_Requested VARCHAR2(1) NULL
    CONSTRAINT CK3APPLICATION_INFO
    CHECK (Financial_Aid_Requested IN ('Y','N'))

  • TS3258 Hello I have upgraded i tunes from 11.0.0.163 to 11.0.4.4 and i am getting 42404 error please help me to fix that error... Thanks

    Hello I have upgraded i tunes from 11.0.0.163 to 11.0.4.4 and i am getting 42404 error please help me to fix that error... Thanks

    Did you ever solve this issue?

  • What does hd macintosh full mean please help I am also getting an error message saying start up disk is full i need to free up some space how do i do this please?

    what does hd macintosh full mean please help I am also getting an error message saying start up disk is full i need to free up some space how do i do this please?

    Also, you may find this link of intereset and value...
    http://macmost.com/what-to-do-when-your-hard-drive-is-full.html

  • I have updated to maverick from mountain lion.initially my mac book pro was snow leopard.the multitrack touch pad swapping the page is not happening in finder,it is only working in safari.please help me how to get that swiping gesture in  finder

    i have updated to maverick from mountain lion.initially my mac book pro was snow leopard.the multitrack touch pad swapping the page to get back to previous page is not happening in finder,it is only working in safari.please help me how to get that swiping gesture in  finder

    Hi..
    I repled to you here >  https://discussions.apple.com/message/25598596#25598596
    Please do not start duplicate topics. It makes it that much harder to assist you.

  • While opening the iTune Store i receive the following error, "The procedure entry point ADAdPolicyEngine_DidEnterSation could not be located in the dynamic link library iAdCore.dll" Please help me to clear this error.

    While opening the iTune Store i receive the following error, "The procedure entry point ADAdPolicyEngine_DidEnterSation could not be located in the dynamic link library iAdCore.dll" Please help me to clear this error.

    I faced the same issue. This solved it for me: Troubleshooting issues with iTunes for Windows updates
    Hope this helps.

  • Please Help,how do i get my iphone 4 to play all my songs from icloud, it is currently only playing just a smal number of songs from my library which is stored in icloud.

    Please Help,how do i get my iphone 4 to play all my songs from icloud, it is currently only playing just a smal number of songs from my library which is stored in icloud.

    There are a number of OS X apps, many free, that will save your messages, allowing to view and print them. 
    http://www.softwarebbs.com/wiki/How_to_transfer_SMS_from_iPhone_to_Mac,_backup_i Phone_SMS_message_on_Mac
    Google, for other options
    Your "other" of 6 GB may include corrupted data or file sytem errors. If after removing the messages there is still >2GB, you will need to restore the phone in iTunes, first using a backup (made after deleting the messages) and if needed as a new iPhone.
    iTunes: Restoring iOS software

  • For updation of IOS 7.1.1 passcode required,I forget my passcode please help how can I get my passcode

    Hello,
    I forget my passcode please help how can I get my it

    You will need to try to restore your iPad from the same computer that you most recently synced to.
    Read this: http://support.apple.com/kb/ht1212
    If you can't do the restore then you will need to try Recovery Mode.
    Read this: http://support.apple.com/kb/ht1808
    Follow the instructions very carefully.

  • Why can't i downgrade to mavericks? i have got some problem with yosmite. i would like to downgrade to mavericks.please help me how to get it ? thanks

    why can't i downgrade to mavericks? i have got some problem with yosmite. i would like to downgrade to mavericks.please help me how to get it ? thanks

    Hi here are a couple of links you may find useful, the first is if you have made a time machine backup, the second if you have not.
    http://osxdaily.com/2014/10/22/downgrade-os-x-yosemite-to-mavericks/
    http://www.macworld.co.uk/how-to/mac-software/revert-back-mavericks-from-yosemit e-3581872/

  • Please help me how to fix error 53 iphone 6 ios 8.1

    please help me how to fix error 53 iphone 6 ios 8.1 when update iphone 6

    Hey there fcaride,
    It sounds like you are unable to finish restoring with iTunes due to this error -1 message. Usually that is associated with security software. Use the steps from the following article to help with that:
    Get help with iOS update and restore errors
    Related errors: 1, 3, 11, 12, 13, 14, 16, 20, 21, 23, 26, 27, 28, 29, 34, 35, 36, 37, 40, 1002, 1004, 1011, 1012, 1014, 1667, or 1669.
    These errors mean that your device or computer might have a hardware issue that stops the update or restore from completing.
    Check that your security software and settings aren't blocking your device from communicating with the Apple update server.
    Then try to restore your iOS device two more times while connected with a cable, computer, and network you know are good.
    Make sure that your security software and settings are allowing communication between your device and update servers.
    If you still see the error message when you update or restore, contact Apple support.
    If the issue persists, I would next use the last section of the following article titled "If your device turns on but gets stuck during start up"
    If your iPhone, iPad, or iPod touch doesn't respond or doesn't turn on
    Thank you for using Apple Support Communities.
    All the very best,
    Sterling

  • Please Help!!! Getting data to a table

    I am having real problems with this I want a table with a header which lists the contents of a file. In this file on each line there are the header titles eg each line is set out the same just containing different parameters etc Event No: 0     Time Elapsed: 1.0 Event String: Algoritm changed Parameter: algo: Monitoring
    In the table the constructor says Object [][] and Object [] please help how do I get my code to compile.
         FileReader file = new FileReader("c:\\projects\\FirstSupport\\logfile2.txt");
              BufferedReader inputfile = new BufferedReader (file);
              Object[] columnNames = {"Event No",
    "Time Elapsed",
    "Event String",
    "Parameter"};
              Object[] values;
              MessageFormat mf = new MessageFormat("Event No:{0,number} Time Elapsed: {1,number} Event String:{2} Parameter:{3,number}");
              text = "Event No: 0     Time Elapsed: 1.0 Event String: Algoritm changed Parameter: algo: Monitoring";
              while ((Line = inputfile.readLine()) != null);
                   System.out.println(text);
                   values = mf.parse(text);
                   int eventNo = ((Number)values[0]).intValue();
                   double time = ((Number)values[1]).doubleValue();
                   String eventString = (String)values[2];
                   int param = ((Number)values[3]).intValue();
    JTable table = new JTable(values,columnNames);

    Hi,
    where is the problem? Does the part reading the file work? If so I would use a class extending DefaultTableModel .
    Have a look at :
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
    Phil

  • Please help  I am suddenly getting the following on my calendar  The server did not recognize your user name or password for account "..." Make sure you enter them correctly.  I depend on it for work

    Please help  I am suddenly getting the following from my calendar  The server did not recognize your user name or password for account “...” Make sure you enter them correctly.I have even tried changing the password and no luck.  I depend on it syncing with mobile me and my phone and I need it for work.

    I have been having the same issue but I think I fixed my problem.  In iCal, click iCal, Preferences, Accounts and retype your password.  That seems to have done the trick for me as far as I can tell.

  • I updated my phone and it cleared everything on it and I don't have an icloud or itunes backup. Please help I need to get my pictures and information back

    I updated my phone and it cleared everything on it and I don't have an icloud or itunes backup. Please help I need to get my pictures and information back

    Sorry, but without a backup in iCloud or iTunes on your computer, your data is gone and can't be restored anymore.

  • I need help Apple!!!! I keep trying to download apps and it always says "youve already purchased this, so it Will be downloaded Now at no additional charge."  And after i try to download it wount download, please help me because im getting tired of this!

    I need help Apple!!!! I keep trying to download apps and it always says "youve already purchased this, so it Will be downloaded Now at no additional charge."  And after i try to download it wount download, please help me because im getting tired of this! Oh and i keep going to the already downloaded apps section and i try to download it but it shows the little icloud symbol and i click it but it wount download it please help!!!!!!!

    Please be aware that you are not communicating with Apple when you post in these forums. The only people who will reply to your posts are your fellow users.
    As to your problem, try resetting the iPhone:
    http://support.apple.com/kb/HT1430
    and then try downloading again. If that doesn't work, you may have to restore your iPhone:
    http://support.apple.com/kb/HT1414
    Hope this helps. Regards.

  • Ichat video error 8 -- Ralph, please help, I have read the prior posts!

    I am trying to video chat with another 10.5.2 machine. We are both using recent Airport Extreme Base Stations. I am connecting via Cox cable modem, RCA 6G24, the other computer is on a DSL modem. When trying to connect, we receive the error 8 message. The other computer has Parallels connected, but we have disabled both the Guest and NAT accounts in the Network sharing tab. Neither machine has internet sharing enabled. We have connected a few times with video, but the majority of the time, we receive the error message below. Any help would be greatly appreciated. One interesting note, we are able to connect for a video chat using an older ibook with 10.4.11 installed on the DSL side and the 10.5.2 machine on Cox cable. We are usually unable to connect 10.5.2 to 10.5.2. Any help would be greatly appreciated.
    The abbreviated version of the message follows:
    Date/Time: 2008-03-23 15:39:42.755 -0400
    OS Version: 10.5.2 (Build 9C7010)
    Report Version: 4
    iChat Connection Log:
    2008-03-23 15:39:08 -0400: AVChat started with ID 3783672204.
    2008-03-23 15:39:08 -0400: kevinjosephrice1: State change from AVChatNoState to AVChatStateWaiting.
    2008-03-23 15:39:08 -0400: 0x9291970: State change from AVChatNoState to AVChatStateInvited.
    2008-03-23 15:39:15 -0400: 0x9291970: State change from AVChatStateInvited to AVChatStateConnecting.
    2008-03-23 15:39:15 -0400: kevinjosephrice1: State change from AVChatStateWaiting to AVChatStateConnecting.
    2008-03-23 15:39:29 -0400: 0x9291970: State change from AVChatStateConnecting to AVChatStateEnded.
    2008-03-23 15:39:29 -0400: 0x9291970: Error -8 (Did not receive a response from 0x9291970.)
    2008-03-23 15:39:29 -0400: kevinjosephrice1: State change from AVChatStateConnecting to AVChatStateEnded.
    2008-03-23 15:39:29 -0400: kevinjosephrice1: Error -8 (Did not receive a response from 0x9291970.)
    Video Conference Error Report:
    10.855543 @SIP/SIP.c:2719 type=4 (900A0015/2)
    [SIPConnectIPPort failed]
    Video Conference Support Report:
    0.687790 @Video Conference/VCInitiateConference.m:1582 type=2 (00000000/0)
    [Connection Data for call id: 1 returns 1
    7.737749 @Video Conference/VCInitiateConference.m:1597 type=2 (00000000/0)
    [Prepare Connection With Remote Data - remote VCConnectionData: 1, local VCConnectionData: 1
    7.744280 @Video Conference/VCInitiateConference.m:1701 type=2 (00000000/0)
    [Initiate Conference To User: u0 with Remote VCConnectionData: 1 with Local Connection Data: 1 conferenceSettings: 1]
    8.854961 @SIP/Transport.c:2362 type=1 (00000000/0)
    [INVITE sip:user@[rip]:16402 SIP/2.0
    Via: SIP/2.0/UDP [lip]:16402;branch=z9hG4bK4df426d77401783d
    Max-Forwards: 70
    To: "u0" <sip:user@[rip]:16402>
    From: "0" <sip:user@[lip]:16402>;tag=627540858
    Call-ID: d3044424-f910-11dc-8df4-9fc4ccab4012@254-56-3-160
    CSeq: 1 INVITE
    Contact: <sip:user@[lip]:16402>;isfocus
    User-Agent: Viceroy 1.3
    Content-Type: application/sdp
    Content-Length: 773
    v=0
    o=kjrice 0 0 IN IP6 lip
    s=0
    c=IN IP6 lip
    b=AS:2147483647
    t=0 0
    a=hwi:288:2:2000
    a=iChatEncryption:NO
    a=bandwidthDetection:YES
    m=audio 16402 RTP/AVP 110 121 12 3 0
    a=rtcp:16402
    a=rtpmap:121 speex/16000
    a=rtpmap:122 speex/8000
    a=rtpmap:113 X-AAC_LD/44100
    a=rtpmap:110 X-AAC_LD/22050
    a=rtpmap:3 GSM/8000
    a=rtpmap:0 PCMU/8000
    a=rtpID:964228453
    m=video 16402 RTP/AVP 123 126 34
    a=rtcp:16402
    a=rtpmap:123 H264/90000
    a=rtpmap:126 X-H264/90000
    a=rtpmap:34 H263/90000
    a=fmtp:34 imagesize 1 rules 30:352:288
    a=framerate:30
    a=RTCP:AUDIO 16402 VIDEO 16402
    a=fmtp:126 imagesize 0 rules 15:640:480:640:480:15
    a=fmtp:123 imagesize 0 rules 15:640:480:640:480:15
    a=rtpID:2253875979
    9.355536 @SIP/Transport.c:2362 type=1 (00000000/0)
    [INVITE sip:user@[rip]:16402 SIP/2.0
    Via: SIP/2.0/UDP [lip]:16402;branch=z9hG4bK4df426d77401783d
    Max-Forwards: 70
    To: "u0" <sip:user@[rip]:16402>
    From: "0" <sip:user@[lip]:16402>;tag=627540858
    Call-ID: d3044424-f910-11dc-8df4-9fc4ccab4012@254-56-3-160
    CSeq: 1 INVITE
    Contact: <sip:user@[lip]:16402>;isfocus
    User-Agent: Viceroy 1.3
    Content-Type: application/sdp
    Content-Length: 773
    v=0
    o=kjrice 0 0 IN IP6 lip
    s=0
    c=IN IP6 lip
    b=AS:2147483647
    t=0 0
    a=hwi:288:2:2000
    a=iChatEncryption:NO
    a=bandwidthDetection:YES
    m=audio 16402 RTP/AVP 110 121 12 3 0
    a=rtcp:16402
    a=rtpmap:121 speex/16000
    a=rtpmap:122 speex/8000
    a=rtpmap:113 X-AAC_LD/44100
    a=rtpmap:110 X-AAC_LD/22050
    a=rtpmap:3 GSM/8000
    a=rtpmap:0 PCMU/8000
    a=rtpID:964228453
    m=video 16402 RTP/AVP 123 126 34
    a=rtcp:16402
    a=rtpmap:123 H264/90000
    a=rtpmap:126 X-H264/90000
    a=rtpmap:34 H263/90000
    a=fmtp:34 imagesize 1 rules 30:352:288
    a=framerate:30
    a=RTCP:AUDIO 16402 VIDEO 16402
    a=fmtp:126 imagesize 0 rules 15:640:480:640:480:15
    a=fmtp:123 imagesize 0 rules 15:640:480:640:480:15
    a=rtpID:2253875979
    10.356086 @SIP/Transport.c:2362 type=1 (00000000/0)
    [INVITE sip:user@[rip]:16402 SIP/2.0
    Via: SIP/2.0/UDP [lip]:16402;branch=z9hG4bK4df426d77401783d
    Max-Forwards: 70
    To: "u0" <sip:user@[rip]:16402>
    From: "0" <sip:user@[lip]:16402>;tag=627540858
    Call-ID: d3044424-f910-11dc-8df4-9fc4ccab4012@254-56-3-160
    CSeq: 1 INVITE
    Contact: <sip:user@[lip]:16402>;isfocus
    User-Agent: Viceroy 1.3
    Content-Type: application/sdp
    Content-Length: 773
    v=0
    o=kjrice 0 0 IN IP6 lip
    s=0
    c=IN IP6 lip
    b=AS:2147483647
    t=0 0
    a=hwi:288:2:2000
    a=iChatEncryption:NO
    a=bandwidthDetection:YES
    m=audio 16402 RTP/AVP 110 121 12 3 0
    a=rtcp:16402
    a=rtpmap:121 speex/16000
    a=rtpmap:122 speex/8000
    a=rtpmap:113 X-AAC_LD/44100
    a=rtpmap:110 X-AAC_LD/22050
    a=rtpmap:3 GSM/8000
    a=rtpmap:0 PCMU/8000
    a=rtpID:964228453
    m=video 16402 RTP/AVP 123 126 34
    a=rtcp:16402
    a=rtpmap:123 H264/90000
    a=rtpmap:126 X-H264/90000
    a=rtpmap:34 H263/90000
    a=fmtp:34 imagesize 1 rules 30:352:288
    a=framerate:30
    a=RTCP:AUDIO 16402 VIDEO 16402
    a=fmtp:126 imagesize 0 rules 15:640:480:640:480:15
    a=fmtp:123 imagesize 0 rules 15:640:480:640:480:15
    a=rtpID:2253875979
    Video Conference User Report:
    0.000000 @:0 type=5 (00000000/16402)
    [Local SIP port]
    0.000041 @:0 type=5 (00000000/16402)
    [Local SIP port]
    10.946797 @Video Conference/VideoConferenceMultiController.m:1474 type=5 (00000000/0)
    [IP And Port Data With Caller IP And Port Data: Obtained 200 bytes of local IP and port data (5 entries). Remote data was 0 bytes (0 entries).
    []

    Hi,
    Thanks for not including the Binary Images part.
    This log indicates your have called out and iChat has moved to the SIP Invite part.
    At this point it is waiting and repeating that SIP invite (after the Visible invite is accepted).
    It is using the "right" ports at your end.
    It says the other end is responding at least to the visible invite and potentially this is also on port 16402.
    However it does not progress.
    See he has two computers on the DSL modem how has he got the ports open for iChat for these two computers ?
    I would suspect that he may have the Airport in Bridge mode (Joined and Existing Network or set it NOT to share an IP) but the modem is doing DHCP and Port Forwarding and the ports are not pointed to the new computer.
    Worse case is he has both devices doing DHCP and at his end he is getting Error 4
    4:53 PM Monday; March 24, 2008

Maybe you are looking for

  • Moving to the end of a result set

    When moving to the end of a result set using the keyboard shortcut Ctrl+End the view of the result moves to the last row, but the current field does not move. So when I use up or down keys after Ctrl-end, I'm back at the top of the result set. The cu

  • I cannot install updates for iMovie, or iPhoto.

    I cannot install updates for iMovie, or iPhoto. It keeps telling me "You have updates for available for other accounts. To update this application sign into the account you used to purchase it."  The thing is, I am logged into the only Apple ID accou

  • Javascript + CF XML Integration

    Hi everyone... I've searched ALL over the net and I can't seem to come up with results on how to do my task. The task seems fairly simple, and I've tried quite a few methods, but I cannot seem to get it to work Here is my goal: 1)I have a simply HTML

  • BPM or multimapping

    I have two files coming in which are sequentially send . one file is for agents and one for carriers I have to generate only one output file based on the data from both the files .Data coming from the files is independent of each other. how to procee

  • Terminal doesn't show changes immediately

    Hi, since some days I have an annoying problem: When I type something, for example 10 x [Return], my xterm doesn't "react" immediately. Nothing happens for at least several seconds. When I switch the window and switch back the input / command is show