Float cannot be dereferenced

Hi,
I get the following compilation error message:
"float cannot be dereferenced"
and i don't know what it meens.
My code was compiling until i add the intValue methode in the last line.
Here is the part of code :
Dimension d,i;
d = getSize(); // i get the size of the frame
i = _imPanel.getSize();       // i get the size of an element in this frame
float hp = i.height/d.height; // i calculate a ratio between those 2 size
float wp = i.width/d.width; // for each dimansion
_imPanel.setPreferredSize(new Dimension((getWidth()*wp).intValue(),(getHeight()*hp).intValue())); 
// and i apply a new dimension to the element int the frame using the ration and the new size of the frame.
As the ratio is a float and Dimension needs int in parameters, i decided to use the intValue methode to cast the float into int.
That's it.

Hello,
Your problem is that you are trying to use a primitive type as if it were an object!
You cannot call methods on the primitive types (int, float, double, etc.). Therefore, your line should be converted from:
Dimension((getWidth()*wp).intValue(),(getHeight()*hp).ntValue()));to Dimension(new Float(getWidth()*wp).intValue(), new Float(getHeight()*hp).intValue()));Which could be done better by directly casting the values:
Dimension((int)(getWidth()*wp), (int)(getHeight()*hp));Manuel Amago.

Similar Messages

  • Error : char cannot be dereferenced

    I wrote this program for my test in high school. I am getting 1 error and cannot fix it. can any1 please tell me how to fix this error. The following is the program and the rror message "-
    I AM NEW HERE so i would really BENEFIT from ANY HELP !
    class testing
              static int[] search(char list[], char target) {
                   int brand[] = new int [list.length];
                   for (int i=0; i<list.length; i++) {
                        if (list[i] == target)
                        brand[i] = target.positionOf();
                   return brand;
              } // end method
              public static void main (String str[]) {
                   char list[] = {'M', 'B', 'A', 'J', 'P', 'J','M', 'J'};
                   char target = (str[0].charAt(0));
                   System.out.print ("The list = ");
                   for (int i =0; i<list.length; i++)
                        System.out.print(list[i] + ", ");
                   System.out.println();
    System.out.println ("Target letter " + target + " has been found in position " + search(list,target) + ".");
              } // end main
         } // end class     
    Error :
    C:\JPadPro\MyProjects\testing.java:14: char cannot be dereferenced
         brand[i] = target.positionOf();
    ^
    1 error
    Finished

    My program question was --> Write a program to find a symbol from a list of symbols. Your search method should return all positions in which the target symbol is found.
    According to your solution I changed to indexOf() but still i get the same error.
    class testing
              static int[] search(char list[], char target) {
                   int brand[] = new int [list.length];
                   for (int i=0; i<list.length; i++) {
                        if (list[i] == target)
                        brand[ i ] = (list[ i ].indexOf(target));
                   return brand;
              } // end method
              public static void main (String str[]) {
                   char list[] = {'M', 'B', 'A', 'J', 'P', 'J','M', 'J'};
                   char target = str[0].charAt(0);
                   System.out.print ("The list = ");
                   for (int i =0; i<list.length; i++)
                        System.out.print(list[i] + ", ");
                   System.out.println();
                   System.out.println ("Target letter " + target + " has been found in position " + search(list,target) + ".");
              } // end main
         } // end class     
    Error =
    The current directory is: C:\JPadPro\MyProjects
    C:\JPadPro\MyProjects\testing.java:14: char cannot be dereferenced
              brand[i] = (list.indexOf(target));
    ^
    1 error
    Finished

  • Character cannot be dereferenced?

    //output from compiler
    partA.java:72: char cannot be dereferenced
                    String theCharacterToBeAString = checkValue.toString();
                                                               ^the code
    public boolean isOperator(char checkValue)
              String theCharacterToBeAString = checkValue.toString();
              if(theCharacterToBeAString.equals("+"))
                   return true;
              else
                   return false;
         any ideas?

    Woops!
    public static boolean isOperator(char checkValue) {
        return checkValue ==  '+';

  • ERROR: int cannot be dereferenced

    hi everyone i am trying to copmile the following code
    public void refreshGUI() {
            MessageBoardQueries MBQ = new MessageBoardQueries();
            Date date = Calendar.getInstance().getTime();
            DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
            String argDate = df.format(date).toString();
            int pNumber = MBQ.queryPending(argDate);
            int aNumber = MBQ.queryAccepted(argDate);
            int dNumber = MBQ.queryDeclined(argDate);
            pendingNumberField.setText(pNumber.toString());
            acceptedNumberField.setText(MBQ.queryAccepted(argDate));
            declinedNumberField.setText(MBQ.queryDeclined(argDate));
        }but i keep getting the error:
    int cannot be dereferenced on the line
    pendingNumberField.setText(pNumber.toString());
    does anyone know why?

    because int is a primitive datatype, hence doesn't inherit from java.lang.Object, and as such doesn't have a toString method
    try Integer.toString(pNumber) or String.valueOf(pNumber). either is equally valid

  • Boolean cannot be dereferenced

    Hi all any help would be great:
    Im getting these errors:
    KhanAccount.java:41: boolean cannot be dereferenced
    for(int i = 0; i < passwd.length(); i++)
    ^
    KhanAccount.java:42: boolean cannot be dereferenced
    if (Character.isDigit(passwd.charAt(i)))
    ^
    KhanAccount.java:45: boolean cannot be dereferenced
    if (passwd.length() >= 6 && hasDigit)
    ^
    3 errors
    This is the code:
    (main method)
    import java.text.*;
    import javax.swing.*;
    public class KhanPassword
    public static void main (String [] args)
    KhanAccount oneacct = new KhanAccount ();
    inputacct (oneacct);
    System.exit(0);
    public static KhanAccount inputacct (KhanAccount aacct)
    /* If an invalid password is entered (or the two entries do not match),
    the user should be prompted to try again. */
    /* Continuously reads a pair of passwords until the two match.*/
    do { // Continuously reads the password until it is a valid one.
    do {
    String password = JOptionPane.showInputDialog("Enter password:\n"
    + "(must be at least six characters long and have at least one digit)");
    aacct.setusername(un);
    /* display a message indicating whether it is valid or not */
    if (!aacct.setPassword(passwd))
    JOptionPane.showMessageDialog(null, "Invalid password!");
    else {
    JOptionPane.showMessageDialog(null, "Valid password!");
    break;
    while (true);
    /* The password should be prompted for twice */
    String reenter = JOptionPane.showInputDialog("Re-enter password:");
    /* the entries should match or a message provided to the user. */
    if (!passwd.equals(reenter))
    JOptionPane.showMessageDialog(null, "Two passwords don't match!");
    else
    JOptionPane.showMessageDialog(null, "Two passwords match!");
    } while (!passwd.equals(reenter));
    return aacct;
    (called method)
    public class KhanAccount
    public String username;
    public boolean password;
    public String reenter;
    public boolean passwd;
    public static void KhanAccount (){};
         public String getusername()
         return username;
         public boolean getpassword()
         return password;
         public void setusername (String un)
         username = un;
    public boolean setPassword()
    password = passwd;
    /* check if contains digit*/
    boolean hasDigit = false;
    for(int i = 0; i < passwd.length(); i++)
    if (Character.isDigit(passwd.charAt(i)))
    hasDigit = true;
    if (passwd.length() >= 6 && hasDigit)
    password = passwd;
    return true;
    } else
    return false;
    }

    Btw, isn't better to initiate hasDigit to true and then when
    a character is wrong set hasDigit = false and quit loop
    with break or so?
    And methods called set.. often returns nothing if they return
    boolean they are often named with is... or so isPasswd
    I've learned basic methods should be divided into three types:
    constructors starts with make..
    modifiers , set..
    predicats , is..
    //jF
    /* check if contains digit*/
    boolean hasDigit = false;
    for(int i = 0; i < passwd.length(); i++)
    if (Character.isDigit(passwd.charAt(i)))
    hasDigit = true;
    if (passwd.length() >= 6 && hasDigit)
    password = passwd;
    return true;
    } else
    return false;
    }

  • "int cannot be dereferenced" error.. help me please

    I'm working with an array list class called PersonList and it uses attributes from a normal class called Person.
    I would like to make this method PrintPerson inside the PersonList class that should search for a specific Person given the ID as parameter to the method. the method should print all info of the Person if found, otherwise a message saying id is not valid.
    I solved it like this:
    public void PrintPerson(int id)
              System.out.println("Enter ID of the person ");
              id = Stdin.readInteger();
              //search the ID if it is in the List
              int i=0;
              while
              ((i<next)&&(!(list.getID().equals(id))))
              i++;
              //if found
              if (i<next)
                   list[i].OutputWindow();}//display the object ouput of this ID
                   else{
                   System.out.println("The following ID: " id "is not valid!");
              }//end if
         }// end of method
    my problem is with this code:
    ((i<next)&&(!(list.getID().equals(id))))
    I get this error "int cannot be dereferenced"
    what should I do? help me please
    -- Matt

    list.getID() == id                                                                                                                                                                                                                               

  • This program show me "int cannot be dereferenced" as error can you help me?

    public class Factorial{
         public static void main (String [] args){
              if (args.length<1){
                   showmsg("a Integer Please");
                   else if (args.length>1){
                        showmsg ("Only a Integer please");
                        else {
                             int n;
                             try {
                                  n= Integer.parseInt(args[0]);
                             catch (NumberFormatException nfe){
                             showmsg ("a Integer not a String please"); //call to chow message method
                        factorial(n);
         //show a message
         private static void showmsg (String texto){
              System.out.println(texto);
         //factorial procedure
         public static void factorial (int n){
              int fac=1;
              for (int i=1;i<=n;i++){
                   fac*=i;
              String resu = fac.toString();
              showmsg(resu);
    }

    Thanks for your help, I did change other lines too... (if some body wish Run)
    try {
            int n;
            n= Integer.parseInt(args[0]);
            factorial(n);
    catch (NumberFormatException nfe){
                //call to show message method
               showmsg ("a Integer not a String please");
               showmsg (nfe.getMessage());
    }

  • Float to string

    why this doest work?
    error: float cannot be dereferenced
    System.out.println(Float.parseFloat(3.0).toString())
    can any expert tell me?
    thx
    your
    terry

    System.out.println(Float.parseFloat(3.0).toString())Not an expert but the parseFloat returns a native which doesn't have a toString method. I would use the other post that creates a new Float() object. Or just take the toString() off and it should work. Natives print just fine. Like in...
    int z = 123;
    String x = "Hello, my tag is " + z + "#";
    // x will print "Hello, my tag is 123#";

  • Clues on how to fix these errors??

    I am not sure if I am should post all of my code or not, but here are the errors I keep getting and I do not know how to over come them. Also I know I should be able to build the frame and do the calculations in the the same program, but I until I get these errors worked out I can't do that. Any suggestions?
    doMort.java [63:1] float cannot be dereferenced
    mortgage= Float.parseFloat(mortgage.getText());
    ^
    doMort.java [64:1] float cannot be dereferenced
    interest = Float.parseFloat(interest.getText());
    ^
    doMort.java [65:1] float cannot be dereferenced
    length = Float.parseFloat(length.getText());
    ^
    doMort.java [77:1] pow(double,double) in java.lang.Math cannot be applied to (float)
    double temp1 = (1-Math.pow(1+r)-t);
    ^
    doMort.java [78:1] possible loss of precision
    found : double
    required: float
    float temp2 = r/temp1;
    ^
    5 errors
    Errors compiling doMort.

    Hi.
    You probably do not need to post all your code.
    The first three errors are basically the same - let's look at the first one:
    you have a variable called mortgage. You declared it to be of some type which is
    not float, and you try to put a float value into it.
    the fourth problem is that you are trying to use the method Math.pow, which needs
    to receive two double arguments. However, you only give it one argument which is float. The
    compiler doesn't like that.
    The last warning tells you that you are in danger of getting a wrong answer, since you are trying
    to calculate the r/temp1 - which gives a result of type double. You take this result and put it into
    a variable that's declared float - and since a double can hold more precision than a float- you might
    lose this precision and hence get a wrong answer there.
    Nimo.

  • Double to float

    I found in APIs, there is a method: floatValue() to transfer double to float.But when I wrote the following code and compiled it, the error is:
    myjava.java:437: double cannot be dereferenced
    float ba=aa.floatValue();
    program:
    double aa=4;
    float ba=aa.floatValue();
    What's the problem in my program?
    Thanks

    That does not work because the floatValue() method exists in the Double wrapper class and not for the double primitive type. You should try either:
    double aa = 4;
    Double d = new Double(aa);
    float ba = d.floatValue();or
    double aa = 4;
    float ba = (float)aa;

  • Int dereferencing error when transforming 2d array

    Int WorkArray = new Int[9];
    WorkArray.set( new int[] { 6, 3, 0, 7, 4, 1, 8, 5, 2 } );
              for( Tloop = 0; Tloop <= 8; Tloop++ )
                   TransForms[0][Tloop].set( WorkArray.getValueAt( Tloop ) );
              }I get the "Int Cannot be Dereferenced" error on the line beginning with TransForms.
    The definition of the array TransForms is private int[][] TransForms = new int[9][9];

    That was a mistake yes, ive refined the code more but it still gives me this damn "Int cannot be dereferenced" error.
             int[] WorkArray = new int[9];
         int[] rotate90 = {6,3,0,7,4,1,8,5,2};
              WorkArray = rotate90;
              for( Tloop = 0; Tloop <= 8; Tloop++ )
                   TransForms[0][Tloop].setInt( WorkArray [Tloop] );
              }basically the 0-8 array represents a 3*3 grid and this code is to create a transformation that represents that grid rotated right by 90 degrees. I have 8 more of these bits of code to do other transformations. Obviously none of them work as yet. But if I get this one fixed then i can apply this fix to the others.

  • Float to []byte

    If I have this float (6.061.970.311.763.627), how to do for get an array of byte from this float (0x158954731256AB)?
    There is not problem if it is a String ("158954731256AB") or two integer (0x00158954 0x731256AB).

    jotremar wrote:
    It is for a network protocol. It only work with bytes. All numbers are in different endianess.
    If a want to send a int (4, for example), I have to send it with endianess (0x04000000). This protocol have numbers more great than int (I use float for it) Do NOT use float just to get numbers bigger than int. For one thing there will be holes--integers that are in float's range that can't be represented by float. ONLY use float or double if you want floating point numbers. If you just need bigger integers, stick to long or BigInteger.
    and I have to make endianess to it (0x0400000000000000 => float = 4).That's wrong for two reasons.
    1. Float is 4 bytes, just like int.
    2. For the third bluddy time, 4 in a Java float is NOT 0x00000004. It is 0x40800000. A float's bite pattern for an integer is NOT the same as an int's bit pattern for the same integer.
    Okay, three reasons, but I already told you the third, and it kind of goes along with #1 anyway, but I'll repeat it:
    3. There are integers that int can represent that float cannot. And there are integers outside of int's range, but still in float's range that float cannot represent.
    [SOME THINGS YOU SHOULD KNOW ABOUT FLOATING-POINT ARITHMETIC|http://java.sun.com/developer/JDCTechTips/2003/tt0204.html#2]
    [What Every Computer Scientist Should Know About Floating-Point Arithmetic|http://docs.sun.com/source/806-3568/ncg_goldberg.html]
    [Another good (slightly simpler) FP explanation|http://mindprod.com/jgloss/floatingpoint.html]
    Edited by: jverd on Sep 10, 2009 3:43 PM

  • Int cannot be deffered error

    Hello,
    I hope this is an appropriate forum for this question. This is not a HW assignment; I have just started Java as a hobby. I think the real problem I have is a lack of sound understanding of how to call methods, and what criteria have to be met to call a method within the main().
    Here is the code:
    public class InconvenientChange3
         public static int quarters;
         public static int dimes;
         public static int nickels;
         public static int pennies;
         public static int sum;
         public static int sum()
                   sum = quarters + dimes + nickels + pennies;
         public static void main(String[] args)
                   System.out.println();
                   int[] values = new int [100];
                   for (int amount = 1; amount < 100; amount ++)
                             quarters = amount/25;
                             int remainder = amount%25;
                             dimes = remainder/10;
                             remainder = remainder%10;
                             nickels = remainder/5;
                             pennies = remainder%5;
                   for (int amount = 1; amount < 100; amount ++ )
                             values[amount] = sum.values[amount];
                             System.out.println(values[amount]);
                   System.out.println();
    The error I get is: int cannot be dereferenced values[amount] = sum.values[amount];
    I have tried troubleshooting this for a while, but can't figure out this error. Thanks so much for your assistance.
    - steve

    Hello,
    Thanks for your response. My intent is to apply the method "sum" (which adds the total number of quarters, dimes, nickels, and pennies) to the elements of the values[ ] array, thus creating a new array that holds the number of coins required for each value.
    So the value at index 1 is 1 (1 penny)
    The value at index 11 is 2 (1 dime, 1 penny)
    The value at index 41 is 4 (1 quarter, 1 dime, 1 nickel, 1 penny)
    etc.
    I played with this a little, and successfully printed the sum for every value by including the statement:
    sum = quarters + dimes + nickels + pennies wihin the first for loop. (So I know my math logic is correct). Now I want to assign these sums to a new array - that's my intent.
    Thanks again for your help and patience.
    Regards,
    steve

  • What does the term dereferenced mean?

    hello, i'm gettin a compile error stating that a char cannot be dereferenced.
    I'm not exactly sure what the error is saying here's the line of code:
    <code>
    if (sentence.charAt(0).equals(word.charAt(0)))
         startedMatch = true;
    </code>
    I'm greatful for any help I get
    thanks!

    so how would I fix it?
    I want to compare two strings, well actually find out if the smaller string is within the larger one using recursion...I was just testing out different ways, and obviously that one doesn't work...

  • Dereferencing problem

    can someone help me, i'm having some problems with the following lines of code:
    int score, end;
    1.if(end.equals("")){
    2.end = 30000;
    3.}               
    4.if(score.equals("")){
    5.score = 1;
    this is giving me the following error for lines 1 and 4:
    " int cannot be dereferenced "

    You are trying to use end and score (variables that are of a primitive type, namely int) as if they were of an Object type. Second, you are trying to compare int's to String values ("").
    An int can't be null, it can't be "" and can only hold signed 32-bit integer values. If you want to compare ints you have to use x == y and not x.equals(y).
    Chuck

Maybe you are looking for

  • Cups / HP Laserjet 4200 network printer

    Cups can get on my nerves bigtime. at first, I just installed cups, and soffice (libreoffice) would , in the 'print dialog' show me a bunch of network printers it found, but when i printed to any of them, the job would just stick to 'in process' in t

  • ClassNotFoundException: oracle.adf.share.http.ServletADFFilter

    We have recently started using ADF and I have been tasked with deploying it to a Apache Tomcat environment. I have a simple 'jspx' with a ADF Data Visualization graph on it, that I have deployed to my local tomcat env using the JDeveloper deployment

  • This table contains no cards. Use Search to view cards

    within communications express, when I go to compose a new message and click on the address book card to select recipients, it says: This table contains no cards. Use Search to view cards yet , when I go to address book I have entries in my personal a

  • How to have spam included with my mail

    I bought an ipod touch 4, and it works great.  There is only one problem.  When I check the apple mail, it doesn't mention the spam folder there at all. Sometimes I get messages from people that go through spam.  I don't want the hassle of turning th

  • Init after some deltas

    Hi Experts, i have a senario We running the one info package with selection critarea company code "ABC" (init & deltas), Now we got new queriment that now we have to take another selection critarea company code "XYZ". What are the steps i have to fol