Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default How to solve "int cannot be dereferenced" error?

    Hello, I'm getting an "int cannot be dereferenced error" with my method. I'm trying to add two rational numbers
    (fractions) together and return the new rational number.
    From what I've read in my book and online, I've figured out that I can't invoked methods on primitives.
    But then how else would I get the numerator and denominator of the two rational numbers?
    Any help is greatly appreciated, thanks!

    Java Code:
    public RationalNumber add(RationalNumber other)
    	{
    		this.numerator = number.getNumerator() * other.getNumerator() 
    			+ number.getDenominator() * other.getDenominator();
    		this.denominator = number.getDenominator() * other.getDenominator();
    		RationalNumber addedNumber = new RationalNumber(addNumerator, addDenominator);
    		return addedNumber;
    	}

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: How to solve "int cannot be dereferenced" error?

    how else would I get the numerator and denominator of the two rational numbers?
    Quite possibly with .numerator and .denominator as you are already doing with "this". But that's only a guess.

    For better, post the Rational class so we can see how it's defined. And the full and exact compiler message. Also say precisely what this method is supposed to do. At the moment you have it doing two things: creating and return a new Rational, and also altering the state of "this".

    -----

    Also you might want to check your formula. a/b +c/d != (ac+bd)/bd

Similar Threads

  1. Replies: 2
    Last Post: 01-24-2011, 12:26 PM
  2. How can I solve "void cannot be dereferenced" error?
    By fervent07 in forum New To Java
    Replies: 2
    Last Post: 04-05-2010, 08:54 PM
  3. How to solve this "Fixtures code" error exception?
    By makerror in forum New To Java
    Replies: 4
    Last Post: 12-02-2009, 02:45 AM
  4. Replies: 2
    Last Post: 11-30-2008, 03:24 PM
  5. How to solve "No compiler error"?
    By iceman in forum New To Java
    Replies: 5
    Last Post: 04-22-2008, 03:37 AM

Posting Permissions

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