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 3229244
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:47:17+00:00 2026-05-17T16:47:17+00:00

Well, I’m trying to create a way of detecting if the user inputs nothing

  • 0

Well, I’m trying to create a way of detecting if the user inputs nothing and clicks ‘OK.’

For example, if the user clicks cancel, I break out of a while loop with the following code:

if (words[i] == null) break; //breaks out of while loop

I tried something along these lines for a user clicking OK:

else if (Character.isDigit(words[i].charAt(0)) && words[i].charAt(0) == JOptionPane.OK_OPTION) break;

to break out of the loop if the user were to click OK, but no dice. I get this exception:

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

OK_OPTION is of type int which is why I converted to int. Does anybody have any ideas of how I can do this?

I found this post about the ‘Cancel’ button but nothing about the ‘OK’ button. Thanks!

  • 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-05-17T16:47:18+00:00Added an answer on May 17, 2026 at 4:47 pm

    When a user enters no input and hits okay, your program is still storing the string in your words array, the string just happens to be blank. An easy way to check if the string is blank is by checking its length, so the code you want could look like:

    // break if user enters blank input
    if( words[i].length() == 0 ) break;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

well, I am trying to include a header file in my project, while the
well I'm trying to create a great playlist of music, only using a sigle
Well, i took a break from RoR for studies, now I am back, I
Well, I was trying to fix this program, and I keep getting the errors
Well, i have the following need: create 3 dropdownlist with dependencies. My table in
Well my windows service has to send out automated emails when the sql database
Well, i saw a Qt Quick Image's Carousel Example in h ttp://developer.qt.nokia.com/wiki/Qt_Quick_Carousel . I
Well it is definitely way faster than the built-in Web-Browser component of .Net Framework.
Well, I've been programming for VB.NET for a while, and now I am interested
Well the subject is the question basically. Are there any version control systems out

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.