• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

float cannot be dereferenced

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
}
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't call methods on float variables.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic