Results 1 to 7 of 7
  1. #1
    san1 is offline Member
    Join Date
    Feb 2014
    Posts
    9
    Rep Power
    0

    Default Error: int cannot be dereferenced

    Hi,

    I'm getting the "int cannot be dereferenced" error for the following code. Any help is appreciated. Thanks:

    public int value()
    {
    int total = 0;

    for (int i = 0; i < wallet.length; i++);
    total += wallet[i];
    }

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,275
    Rep Power
    6

    Default Re: Error: int cannot be dereferenced

    The only thing I see wrong is that you have a ; too many and you're missing an opening { in your for loop

    Java Code:
    public int value()
    {
    int total = 0;
    
    for (int i = 0; i < wallet.length; i++);  // this semicolon is wrong
    total += wallet[i];
    }
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    san1 is offline Member
    Join Date
    Feb 2014
    Posts
    9
    Rep Power
    0

    Default Re: Error: int cannot be dereferenced

    Thanks. I modified the code but still get the same error:

    public int value()
    {
    int total = 0;

    for (int i = 0; i < wallet.length; i++)
    {
    total += wallet[i];
    }
    }

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,275
    Rep Power
    6

    Default Re: Error: int cannot be dereferenced

    Then wallet is probably not an int array but a single int. I can't see that because you refuse to post more code.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    san1 is offline Member
    Join Date
    Feb 2014
    Posts
    9
    Rep Power
    0

    Default Re: Error: int cannot be dereferenced

    public class Wallet
    {
    // max possible # of banknotes in a wallet
    private static final int MAX = 10;

    private int contents[];
    private int count; // count # of banknotes stored in contents[]
    private int wallet;

    .................
    ...............
    ..............
    /**
    * To compute the value of bank notes in the wallet & return the number in dollars
    */
    public int value()
    {
    int total = 0;

    for (int i = 0; i < wallet.length; i++)
    {
    total += wallet[i];
    }
    }


    Hope this helps.

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,275
    Rep Power
    6

    Default Re: Error: int cannot be dereferenced

    See? Wallet is not even an array.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,923
    Rep Power
    5

    Default Re: Error: int cannot be dereferenced

    And you need a proper return statement.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. How to solve "int cannot be dereferenced" error?
    By cheezncrackers in forum New To Java
    Replies: 1
    Last Post: 12-14-2011, 08:43 AM
  2. ERROR - char cannot be dereferenced HELP
    By jonytek in forum New To Java
    Replies: 6
    Last Post: 05-04-2011, 07:54 AM
  3. int cannot be dereferenced
    By jackrush in forum Advanced Java
    Replies: 2
    Last Post: 11-12-2010, 09:47 AM
  4. How can I solve "void cannot be dereferenced" error?
    By fervent07 in forum New To Java
    Replies: 2
    Last Post: 04-05-2010, 09:54 PM
  5. Replies: 2
    Last Post: 11-30-2008, 04:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •