Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8560639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:19:18+00:00 2026-06-11T16:19:18+00:00

I am encountering an error when user doesn’t type anything into input statement. I

  • 0

I am encountering an error when user doesn’t type anything into input statement. I thought of using Try/Catch blocks to instead throw exception to set boolAskRepeat to true which should skip to the end of the code and repeat the loop.

This doesn’t work, and I believe I’m missing something but I’m not sure what… It still throws exception saying:

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0
    at java.lang.String.charAt(Unknown Source)
    at ITSLab03.main(ITSLab03.java:34)

Which is this line of code: inputStatus = input.readLine().toLowerCase().charAt(0);

What am I doing wrong here?

while (boolAskStatus == true)
{
    System.out.print("Employment Status (F or P): ");

    try 
    { 
        inputStatus = input.readLine().toLowerCase().charAt(0); 

        if (inputStatus == "f".charAt(0))
        {
            boolAskStatus = false;

            String stringCheckSalary = null;
            boolean boolCheckSalary = true;
            while (boolCheckSalary == true)
            {
                // some code
            }

            outputData(inputName, inputStatus, calculateFullTimePay(inputSalary));
        }
        else if (inputStatus == "p".charAt(0))
        {
            // some code                

            outputData(inputName, inputStatus, calculatePartTimePay(inputRate, inputHours));
        }
        else boolAskStatus = true;

    } 
    catch (IOException e) { boolAskStatus = true; }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:19:20+00:00Added an answer on June 11, 2026 at 4:19 pm

    You need to catch StringIndexOutOfBoundsException as well (If you observe the stack trace properly this is the exception you are getting)

      catch (StringIndexOutOfBoundsException e) {
                boolAskStatus = true;  
          }
    

    (or)
    catch Exception which catches all runtime exceptions

    catch (Exception e) {
                    boolAskStatus = true;  
              }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm encountering an error sprintf statement. I added a printf command to help investigate,
Scenario While using the Maven Ant Task artifact:deploy , I'm encountering the error java.lang.OutOfMemoryError:
I'm encountering this error : Membership credential verification failed. when I try to login
I read SO about another user encountering similar error , but this error is
I am encountering this error when I am loading an Ad Hoc build of
I am encountering an error when I am trying to deploy my DB project.
I'm encountering an error I can't seem to figure out in my bare-bones program
I seem to be encountering an error when reading from a text file. This
I've been doing some simple shaders and Im encountering an error that happens randomly,
I am encountering the following error in my app. upon starting it: [3/26/12 13:05:26:109

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.