Results 1 to 4 of 4
  1. #1
    Darkzombies is offline Senior Member
    Join Date
    Nov 2012
    Posts
    105
    Rep Power
    0

    Default Says can't convert from boolean to int, no boolean is even involved.

    Java Code:
    public class Location {
    
    	private int row;
    	private int column;
    	private int tileAboveRow;
    	private Tile tileAbove;
    	private Map map = new Map(5, 5);
    	
    	public Location(int row, int column){
    		this.row = row;
    		this.column = column;
    	}
    	
    	public int getRow(){
    		return row;
    	}
    	
    	public int getColumn(){
    		return column;
    	}
    	
    	public Tile getTileAbove(){
    		tileAboveRow = row - 1;
    		for(int x = 0; x > map.getTiles().size(); x++){
    			if(tileAboveRow = map.getTiles().get(x).getY()){
    				
    			}
    		}
    	}
    }
    This specifically:

    Java Code:
    		tileAboveRow = row - 1;
    		for(int x = 0; x > map.getTiles().size(); x++){
    			if(tileAboveRow = map.getTiles().get(x).getY()){
    getTiles gets an List from the map class, get(x) grabs the tile from x point in the list, getY gets the Y positioning (Or column, since it's grid based)

    I really can't tell the problem, I don't think any of those methods use a boolean.

    Here's the map class:

    Java Code:
    import java.util.ArrayList;
    import java.util.List;
    
    public class Map {
    
    	private List<Tile> tiles = new ArrayList<Tile>();
    	private int numRows;
    	private int numColumns;
    	
    	public Map(int numRows, int numColumns){
    		this.setNumRows(numRows);
    		this.setNumColumns(numColumns);
    	}
    
    	public List<Tile> getTiles() {
    		return tiles;
    	}
    
    	public int getNumRows() {
    		return numRows;
    	}
    
    	public void setNumRows(int numRows) {
    		this.numRows = numRows;
    	}
    
    	public int getNumColumns() {
    		return numColumns;
    	}
    
    	public void setNumColumns(int numColumns) {
    		this.numColumns = numColumns;
    	}
    }

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

    Default Re: Says can't convert from boolean to int, no boolean is even involved.

    I really can't tell the problem, I don't think any of those methods use a boolean.
    None of the methods may involve a boolean (as argument or return value), but that's not what the compiler is grumbling about. If-statements require some boolean valued expression and you have written:

    Java Code:
    if(tileAboveRow = map.getTiles().get(x).getY()) {
    And Java is picky about saying foo=bar cannot be considered a boolean valued expression.

  3. #3
    Darkzombies is offline Senior Member
    Join Date
    Nov 2012
    Posts
    105
    Rep Power
    0

    Default Re: Says can't convert from boolean to int, no boolean is even involved.

    So in simple terms I'm an idiot for not using two equal signs. I can't argue with that logic xD

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

    Default Re: Says can't convert from boolean to int, no boolean is even involved.

    It happens all the time! I'm glad you've got it sorted out.

    In some languages you can say foo=bar and have the result used as a boolean (whether bar's value is nonzero). I think Java's convention was a deliberate break from C because that usage is error prone.

Similar Threads

  1. Boolean help
    By alphasil in forum New To Java
    Replies: 27
    Last Post: 10-28-2012, 12:59 AM
  2. Replies: 1
    Last Post: 11-01-2011, 06:35 PM
  3. Replies: 3
    Last Post: 09-13-2011, 01:01 AM
  4. boolean error help when no boolean is given
    By drewtrcy in forum New To Java
    Replies: 18
    Last Post: 05-05-2011, 10:04 AM
  5. convert boolean to string
    By newbiejava in forum New To Java
    Replies: 3
    Last Post: 07-22-2010, 04:32 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
  •