wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes float cannot be dereferenced Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "float cannot be dereferenced" Watch "float cannot be dereferenced" New topic
Author

float cannot be dereferenced

Erik Evertsen
Greenhorn

Joined: Oct 08, 2004
Posts: 6
I made my first JAVA program to try it out, but when I compile the source code I get the message: "C:\Documents and Settings\E. Evertsen\Bureaublad\Muziekcalculator.java:44: float cannot be dereferenced flsdtextfield.setText(stuitkomst);". What's the problem? Thanx allready.


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Muziekcalculator extends JFrame implements ActionListener{
protected JTextField cmbtextfield;
protected JTextField bfmtextfield;
protected JTextField sdtextfield;
float flcmbtextfield;
float flbfmtextfield;
float flsdtextfield;
float uitkomst;

public Muziekcalculator() {
super("Muziekcalculator");
setSize(500, 500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
Container mcpane = getContentPane();
FlowLayout mclayout = new FlowLayout();
JLabel cmblabel = new JLabel("Capaciteit MB: ", JLabel.LEFT);
JLabel bfmlabel = new JLabel("Bitfrequentie Muziek: ", JLabel.LEFT);
JLabel sdlabel = new JLabel("Speelduur: ", JLabel.LEFT);
cmbtextfield = new JTextField(4);
bfmtextfield = new JTextField(3);
sdtextfield = new JTextField(8);
sdtextfield.setEnabled(false);
mcpane.add(cmblabel);
mcpane.add(bfmlabel);
mcpane.add(sdlabel);
mcpane.add(cmbtextfield);
mcpane.add(bfmtextfield);
mcpane.add(sdtextfield);
cmbtextfield.addActionListener(this);
bfmtextfield.addActionListener(this);
}
public void actionPerformed(ActionEvent mcactionevent) {
String stcmbtextfield = cmbtextfield.getText();
String stbfmtextfield = bfmtextfield.getText();
flcmbtextfield = Float.parseFloat(stcmbtextfield);
flbfmtextfield = Float.parseFloat(stbfmtextfield);
uitkomst = flcmbtextfield * 1024 / (flbfmtextfield / 8);
String stuitkomst = Float.toString(uitkomst);
flsdtextfield.setText(stuitkomst);
}
}
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
You can't call methods on float variables.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Krishnan Loganathan
Greenhorn

Joined: Apr 24, 2004
Posts: 23
Hey Erik,
you cannot call a method over primitive variables. Even though, it is Float means also, u can't call setXXXX methods. since, Float is a immutable class/object. I think so, u have to display the result in the form. so u can call the following st., instead of that one.

sdtextfield.setText(stuitkomst);

Regards,
Loga
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: float cannot be dereferenced
 
Similar Threads
Exception in thread "main"...
Can't Update Record ?
Adding Record Problem in JDBC ?
Exception in thread "main" java.lang.IllegalArgumentException: illegal component position
netbeans 7.1 errors