Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: What's wrong with my code?

  1. #1
    Junior Member
    Join Date
    Nov 2021
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default What's wrong with my code?

    import javax.swing.JOptionPane;
    public class GUI {

    public static void main(String[] args) {

    String name = JOptionPane.showInputDialog("Enter your Name");
    JOptionPane.showMessageDialog(null, "Hello"+name);

    int age = Integer.parseInt(JOptionPane.showInputDialog("Ente r your age"));
    JOptionPane.showMessageDialog(null, "You are "+age+" years old");

    double height = Integer.parseInt(JOptionPane.showInputDialog("Ente r you height"));
    JOptionPane.showMessageDialog(null, "You are "+height+" cm tall");


    }

    }



    - I'm new to this please help

    Exception in thread "main" java.lang.NumberFormatException: For input string: ""

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: What's wrong with my code?

    java.lang.NumberFormatException: For input string: ""
    It looks like the user did not enter a valid value.
    The code needs to test what the user entered BEFORE trying to parse it as a number.

    Another way would be to wrap the statement in a try{}catch block to catch any exception in the parse statement.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. what's wrong with this code ?? HELP
    By Roosh in forum What's Wrong With My Code?
    Replies: 7
    Last Post: June 14th, 2014, 10:35 AM
  2. [SOLVED] can anyone help me what is wrong with my code?
    By marc172 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 22nd, 2013, 09:53 PM
  3. What is wrong with my code?
    By docthoi in forum Java Theory & Questions
    Replies: 13
    Last Post: February 3rd, 2013, 05:33 PM
  4. What is wrong with my code ?
    By rajarshi in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 11th, 2013, 10:54 PM
  5. What is wrong with this code?
    By A19 in forum What's Wrong With My Code?
    Replies: 15
    Last Post: August 11th, 2011, 09:45 PM