Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parse.Float error

Status
Not open for further replies.

Vandy02

Programmer
Jan 7, 2003
151
0
0
US
I am trying to compile a program but receive errors.
I am using jdk1.3 and j2sdk1.4.2 on separate machines.

Errors are:
cannot resolve symbol
symbol: method parseFloat (java.lang.String)
location: class Float
float x = Float.parseFloat(xString)
and receive the same for float y

Is thier an upgrade or soemthing I else I need to do?
Any help would be greatly appreciated.

The following is my script:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class AddFloat extends Applet implements ActionListener{

TextField txtX = new TextField();
TextField txtY = new TextField();
Panel pnlCenter = new Panel();

Label lblAnswer = new Label();
Button btnAdd = new Button("Add 'em up");
Panel pnlSouth = new Panel();

public void init(){
//main layout
setLayout(new BorderLayout());
add(pnlCenter, BorderLayout.CENTER);
add(pnlSouth, BorderLayout.SOUTH);

//center panel
pnlCenter.setLayout(new GridLayout(3,2));
pnlCenter.setFont(new Font("SansSerif", Font.BOLD, 20));
pnlCenter.add(new Label("X:"));
pnlCenter.add(txtX);
pnlCenter.add(new Label("Y:"));
pnlCenter.add(txtY);
pnlCenter.add(new Label("X + Y"));
pnlCenter.add(lblAnswer);

//south panel
pnlSouth.setLayout(new FlowLayout());
pnlSouth.add(btnAdd);
btnAdd.addActionListener(this);

} // end init

public void actionPerformed(ActionEvent e){

Float xWrapper = new Float(txtX.getText());
Float yWrapper = new Float(txtY.getText());

float x = xWrapper.floatValue();
float y = yWrapper.floatValue();
String result = String.valueOf(x + y);
lblAnswer.setText(result);

} // end actionPerformed

} // end class def



import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class AddFloat extends Applet implements ActionListener{

TextField txtX = new TextField();
TextField txtY = new TextField();
Panel pnlCenter = new Panel();

Label lblAnswer = new Label();
Button btnAdd = new Button("Add 'em up");
Panel pnlSouth = new Panel();

public void init(){
//main layout
setLayout(new BorderLayout());
add(pnlCenter, BorderLayout.CENTER);
add(pnlSouth, BorderLayout.SOUTH);

//center panel
pnlCenter.setLayout(new GridLayout(3,2));
pnlCenter.setFont(new Font("SansSerif", Font.BOLD, 20));
pnlCenter.add(new Label("X:"));
pnlCenter.add(txtX);
pnlCenter.add(new Label("Y:"));
pnlCenter.add(txtY);
pnlCenter.add(new Label("X + Y"));
pnlCenter.add(lblAnswer);

//south panel
pnlSouth.setLayout(new FlowLayout());
pnlSouth.add(btnAdd);
btnAdd.addActionListener(this);

} // end init

public void actionPerformed(ActionEvent e){

Float xWrapper = new Float(txtX.getText());
Float yWrapper = new Float(txtY.getText());

float x = xWrapper.floatValue();
float y = yWrapper.floatValue();
String result = String.valueOf(x + y);
lblAnswer.setText(result);

} // end actionPerformed

} // end class def



 
Hi,

I copy/paste both of your classes and compiled in my machine using j2sdk1.4.1 and both compile without warnings/errors. I think you need to check your path and classpath environment variables.


Andres Estrada
Technical Oracle Consultant
 
I copy/paste the first of your classes and compiled in my machine using j2sdk1.4.2 and compiled without warnings/errors. Like Andres said "check your path and classpath environment variables".
Maybe compiling with the "-verbose" parameter can give you more info.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top