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

  • Home
  • SEARCH
  • 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 7650621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:17:52+00:00 2026-05-31T11:17:52+00:00

I am busy with a project for school where I use the InputDialogbox to

  • 0

I am busy with a project for school where I use the InputDialogbox to get the hostname from the user so as to make a client socket connection.

There are two things that puzzle me a bit.

Firstly I make a connection Server Side and then I make the client connection as follow.

input = JOptionPane.showInputDialog(null, "Please enter host name to access" +
                  "server(dotted number only)...see number on frame", "name",
                   JOptionPane.INFORMATION_MESSAGE); 

clientSocket = new Socket(input, 7777);

what puzzles me as that if I press enter in the Dialogue box without making any entry…i.o.w without specifying the IPAddress the connection to the socket is made regardless. Why is that?

To overcome this ‘problem’ I decided to try to get the user to make an entry in the dialogue box

if(input.equals(""))
{
    throw new EmptyFieldsException();
}

The thing is that now if I click on cancel I get a NullPointerException.
How can I cancel the Dialogue box without getting this exception?

Kind regards
Arian

  • 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-31T11:17:54+00:00Added an answer on May 31, 2026 at 11:17 am

    Just do:

    input = JOptionPane.showInputDialog(null,"host name", "name", JOptionPane.INFORMATION_MESSAGE); 
    
    if (input != null && input.equals("")) {
        clientSocket = new Socket(input, 7777);
        // Socket created
    } else {
        // Else not ...
    

    You don’t have to throw an exception, you can just skip the socket creation when the input is bad. You can create an else branch where you notice the user, too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are busy developing a Java web service for a client. There are two
I´m busy converting an existing project from an Ant build to one using Maven.
i'm busy with a school project and I have to build a web app.
I am busy with a school project where I query a database based on
I'm currently busy on a project where I need to use an external accessory
I'm currently busy writing business rules and user stories for a project I'm on.
I have been busy in my project creating a webapp (in struts) that manages
I'm busy with an asignment where i have to make a graphical interface for
I am busy on a project that involves calling the API's of nine other
I'm busy on a small project to convert an Access2003 db to .NET. I

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.