The Artima Developer Community
Sponsored Link

Java Answers Forum
Problem with Java Code

1 reply on 1 page. Most recent reply: Nov 29, 2003 4:07 PM by Senthoorkumaran Punniamoorthy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Char

Posts: 2
Nickname: charbrad
Registered: Nov, 2003

Problem with Java Code Posted: Nov 29, 2003 11:27 AM
Reply to this message Reply
Advertisement
I have a problem with my code...I am trying to create a JFrame that
holds names and phone numbers in a file. This works ok it is just my
output, I do not get the phone number I have entered. For Example
when I enter 1234567899 as the phone number my output is
96000990209E-308. I think is has something to down with the following
segment of my code:

public void actionPerformed(ActionEvent e1)
{
double phoneNums;

try
{
phoneNums = Double.parseDouble(num.getText());
ostream.writeUTF(name.getText());
ostream.wr iteUTF(num.getText());
ostream.writeDouble(phoneNums);
name.setText("");
num.set Text("");
}
catch(NumberFormatException e2)
{
System.err.println("Invalid Phone Number");
}
catch(IOException e3)
{
System.err.println("Error writing to file");
System.exit(1);
}
}
}

Can someone please take a look at it and let me know.


Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: Problem with Java Code Posted: Nov 29, 2003 4:07 PM
Reply to this message Reply
Use Strings to handle Phone Numbers rather than Double.

Flat View: This topic has 1 reply on 1 page
Topic: Using different set of Core Java APIs with JVM Previous Topic   Next Topic Topic: Course Work

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use