Results 1 to 6 of 6
  1. #1
    AidoP is offline Learner
    Join Date
    Nov 2012
    Location
    Margaret River
    Posts
    7
    Rep Power
    0

    Default Type mismatch: cannot convert from int to boolean even though nothing is a boolean!

    I am getting an error here:
    Java Code:
    	public boolean getIsInAir(){
    		int num = getY();
    		if(num = world.getWorldHeight()){
    			return false;
    		}else{
    			return true;
    		}
    	}
    that is a type mismatch. world.getWorldHeight() returns an int.

    Anything wrong with my code is usually to do with my selftaughtness(if thats a word :D).

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,618
    Rep Power
    5

    Default Re: Type mismatch: cannot convert from int to boolean even though nothing is a boolea

    In your logical if, try == instead of =

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    AidoP is offline Learner
    Join Date
    Nov 2012
    Location
    Margaret River
    Posts
    7
    Rep Power
    0

    Default Re: Type mismatch: cannot convert from int to boolean even though nothing is a boolea

    Thanks, I always forget about that. I feel dumb now.

  4. #4
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    130
    Rep Power
    0

    Default Re: Type mismatch: cannot convert from int to boolean even though nothing is a boolea

    Quote Originally Posted by AidoP View Post
    Thanks, I always forget about that. I feel dumb now.
    no need to feel dumb, everybody has to learn.
    Never give up.

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

    Default Re: Type mismatch: cannot convert from int to boolean even though nothing is a boolea

    Quote Originally Posted by AidoP View Post
    Anything wrong with my code is usually to do with my selftaughtness(if thats a word :D).
    Self-education ;)

    Tip: turn the ordering around in the future.

    Java Code:
    public boolean getIsInAir(){
        int num = getY();
        if(world.getWorldHeight() = num){
            return false;
        }else{
            return true;
        }
    }
    see what (different) error this produces. Perhaps still not 100% logical at first glance, but it is slightly less confusing.

  6. #6
    AidoP is offline Learner
    Join Date
    Nov 2012
    Location
    Margaret River
    Posts
    7
    Rep Power
    0

    Default Re: Type mismatch: cannot convert from int to boolean even though nothing is a boolea

    Thanks. I get that one alot ;D
    Last edited by AidoP; 07-12-2013 at 01:23 AM. Reason: Bad grammar :O

Similar Threads

  1. Replies: 3
    Last Post: 05-11-2013, 06:27 AM
  2. Boolean: different two type of declare
    By hqt in forum New To Java
    Replies: 5
    Last Post: 11-24-2011, 08:23 AM
  3. Replies: 3
    Last Post: 09-13-2011, 12:01 AM
  4. convert boolean to string
    By newbiejava in forum New To Java
    Replies: 3
    Last Post: 07-22-2010, 03:32 PM
  5. Replies: 2
    Last Post: 11-16-2007, 01:24 PM

Tags for this Thread

Posting Permissions

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