This part of the code captures input and converts string values to relavent primitive types,using Wrapper classes. Here is the code: String name = JOptionPane.showInputDialog( null, "Enter your name here : " ); String inputint = JOptionPane.showInputDialog( null, "Enter your age here : " ); int age = Integer.parseInt( inputint ); String inputsal = JOptionPane.showInputDialog( null, "Enter your salary here : " ); float sal = Float.parseFloat( inputsal ); When I compile it gives error at last line which parses float from the string. Why can't we use the parseFloat similar to parseInt? Thanks..
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
posted
0
I don't get any error using jdk 1.3 beta on Windows 98. What error exactly are you getting?
"I'm not back." - Bill Harding, Twister
Suresh Ray
Ranch Hand
Joined: Feb 21, 2000
Posts: 55
posted
0
I am working on an IDE, JDeveloper, which uses JDK 1.2, and it gives an error as : method parseFloat(java.lang.String)not found in class java.lang.Float
Thandapani Saravanan
Ranch Hand
Joined: Oct 17, 1999
Posts: 117
posted
0
I don't get any error in JDK 1.2.2 compiler.
Saravanan
Chris Pocock
Greenhorn
Joined: Mar 11, 2002
Posts: 13
posted
0
I get an error when I try the same thing. Do you have to import a special package for these? If its just my JDK, where can I download the lastest one? Thanks -Chris
<i>I'm currently reading 'How to program Java' by Deitel</i><br /><b>I am still learning, so be kind. I also know C++, by the way</b>
"face_master", The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp. We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please edit your profile and select a new name which meets the requirements. Thanks. Dave ps: really, please read the Naming standards, you didn't even come close!
Chris Pocock
Greenhorn
Joined: Mar 11, 2002
Posts: 13
posted
0
I downloaded the JDK 1.3 from that link and set my compiler (RealJ) to know where it is on my computer, but I still get the following errors:
The problem is obviously in these two strings:
Does anybody know what i'm doing wrong?
Rob Ross
Bartender
Joined: Jan 07, 2002
Posts: 2205
posted
0
method names always start with a lowercase letter. Look at the JavaDoc for the API libraries. It documents all the methods in all the classes. the method you want is parseInt(), not ParseInt(). Java is case-sensitive.
Chris Pocock
Greenhorn
Joined: Mar 11, 2002
Posts: 13
posted
0
Whoa sorry. I'm a C++ programmer so I guess its a force of habit...
Chris Pocock
Greenhorn
Joined: Mar 11, 2002
Posts: 13
posted
0
Hand on...I just tried to recompile then I got another error (GRR!). Here it is
Another great source to assist along the path of learning Java is Sun's Java Tutorial. ---- Hint: Perhaps what you wanted to do before was use one of the String.valueOf methods. Good Luck, -Dirk Schreckmann [ March 11, 2002: Message edited by: Dirk Schreckmann ]
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
posted
0
Technically speaking, at what point was this thread hijacked? Was it before or after this post? -Dirk Schreckmann Newest member of Hijackers Anonymous [ March 11, 2002: Message edited by: Dirk Schreckmann ]
Paul Stevens
Ranch Hand
Joined: May 17, 2001
Posts: 2823
posted
0
This thread wasn't hijacked at all. He was having small problems that looking at a tutorial and/or the API would solve. That is until you brought up hijacking threads.
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
posted
0
Thanks for the clarification Paul. I was curious as to just how sensitive the Police were to hijacking. Your position seems perfectly reasonable. [ March 11, 2002: Message edited by: Dirk Schreckmann ]
Rob Ross
Bartender
Joined: Jan 07, 2002
Posts: 2205
posted
0
Originally posted by Chris Pocock: Hand on...I just tried to recompile then I got another error (GRR!). Here it is
If you look up the API documentation for String, you'll see there is no such method in the String class called "parseString()"; If you're trying to create a String object from an int value, you want to use String.valueOf(int value); If you want to parse a String value and return an int, you would use Integer.parseString(String intString); Again, you need to become familiar with the JavaDoc (documentation for the java API).