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 4 of 4

Thread: Problem with calculator in awt

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    1
    My Mood
    Cheerful
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking Problem with calculator in awt

    Dear Friends,

    I am facing problem during calculation in my awt calculator. It is showing NumberFormatException. Can your please help me to fix it. Below is part of code.

    if(e.getSource()==b14)//On button 14, label is "/"
    {
    String v1=tf.getText().toString();
    num1=num1+Integer.parseInt(v1);//num1 is as integer variable
    tf.setText(""); //tf means textField
    }else
    if(e.getSource()==b25)
    {
    String v2=tf.getText().toString();
    num2=num2+Integer.parseInt(v2);
    result=num1/num2;
    tf.setText(String.valueOf(result));
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Problem with calculator in awt

    Welcome to the Forum! Please read this topic to learn how to post code correctly and other useful tips for newcomers.

    Please post your code correctly per the above link. Copy and paste errors - exactly and in their entirety - that you want help with.

  3. #3
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: Problem with calculator in awt

    Cannot see anywhere where you declared any of your ;num;
    variables? Show the full code to the method, what is passed to it
    and then peeps can follow it better.
    NumberFormatException
    What do you think that is telling you? Look at your numerical
    and what form at they use - if they change to another undeclared
    format for example.

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

  4. #4
    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: Problem with calculator in awt

    Also please copy the full text of the error message (it shows where the error happened) and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [Java AWT (No Swing)] - Problem with hiding user-drawn graphics
    By Chassy13 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 16th, 2014, 11:13 AM
  2. Replies: 36
    Last Post: July 25th, 2011, 10:27 AM
  3. Calculator Using AWT
    By Allicat in forum What's Wrong With My Code?
    Replies: 7
    Last Post: May 17th, 2011, 06:49 AM
  4. Stop a while loop with an awt button, problem
    By frx08 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 20th, 2011, 08:24 AM
  5. simple game with swing and awt problem
    By Pulse_Irl in forum AWT / Java Swing
    Replies: 2
    Last Post: October 12th, 2010, 02:04 PM