Results 1 to 2 of 2
- 09-28-2010, 10:07 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 8
- Rep Power
- 0
Getting show dialog box to generate properly
Hi, I have a feeling I'm gonna feel pretty dumb when someone helps me with this. I'm really really new and am probably over my head with this stuff but my determination to learn is relentless. I have get the user to type in their phone number in the dialog box and show their number in this format nnn nnn nnnn with spaces but i should assume whenever they type it in that it will be written like so: nnn-nnn-nnnn. Everytime I try I get thrown this exception
--------------------Configuration: <Default>--------------------
Exception in thread "main" java.lang.NumberFormatException: For input string: "nnn-nnn-nnnn"
at sun.misc.FloatingDecimal.readJavaFormatString(Floa tingDecimal.java:1224)
at java.lang.Double.parseDouble(Double.java:510)
at Chapter3Question66.main(Chapter3Question66.java:16 )
Process completed.
any help would be greatly appreciated.
p.s. here is a copy of what i've written:
/* Chapter 3 Question 66
* V. H.
*/
import javax.swing.JOptionPane;
public class Chapter3Question66
{
public static void main( String [] args)
{
String input = JOptionPane.showInputDialog( null, "Please enter your telephone number" );
Double number = Double.parseDouble( input );
JOptionPane.showMessageDialog( null, " Your telephone number is " + number );
}
}
- 09-28-2010, 10:26 PM #2
Read the API doc for the method: parseDouble()
What kind of data will it accept without a problem?
What kind of Exceptions does it throw if the input is wrong?
You need to use another technique to parse the input String to extract the data in the format you want it in.
What formats can the user enter the input in?
For each one you need to write specific code to extract the data you want.
Similar Threads
-
show Message Dialog
By akritc in forum AWT / SwingReplies: 7Last Post: 06-10-2010, 02:49 PM -
how to show web browser in mobile app or is it possible to show it in textArea
By Basit781 in forum CLDC and MIDPReplies: 3Last Post: 05-27-2010, 10:54 AM -
How to show or open a file download or file save dialog box
By java_bond in forum New To JavaReplies: 0Last Post: 03-05-2010, 04:21 AM -
show Confirm Perspective Switch dialog box
By mostafa in forum EclipseReplies: 0Last Post: 11-22-2008, 11:47 AM -
netbeans 6.0 not show commpunent or show blank page
By fahimaamir in forum NetBeansReplies: 1Last Post: 01-26-2008, 06:20 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks