Results 1 to 3 of 3
  1. #1
    cstampar is offline Member
    Join Date
    Dec 2011
    Posts
    4
    Rep Power
    0

    Default Need help with error message!

    So I am writing a for loop to run through an array of objects. I need to see if one of the data values in the object, a height value, is greater than or equal to another height value that I passed to the method from the main class.

    code/
    public void reapForest(int rHeight) {


    for (index = 0; index < forestArray.length; index++) {
    if (forestArray[index] >= rHeight) {
    System.out.print("Cut " + (index+1) + printing);
    forestArray[index] = new Tree();
    System.out.print("New " + (index+1) + printing);
    }
    /code

    and this is the error i get:


    Java christopherstampar$ javac ForestryMain.java
    ./Forest.java:33: operator >= cannot be applied to Tree,int
    if (forestArray[index] >= rHeight) {
    ^

    I think its because i am trying to compare an object to an int? not sure how to fix, any help would be greatly appreciated!

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default Re: Need help with error message!

    You're right, that's what it means: you can't compare a Tree with an int. You need to have a method in your Tree class that returns an int (a height of the tree?) and compare against that.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    cstampar is offline Member
    Join Date
    Dec 2011
    Posts
    4
    Rep Power
    0

    Default Re: Need help with error message!

    Thanks so much, compiles now!

Similar Threads

  1. Error Message
    By Bimz in forum New To Java
    Replies: 2
    Last Post: 09-11-2011, 01:01 PM
  2. 'else' without 'if' error message
    By jim01 in forum New To Java
    Replies: 6
    Last Post: 04-22-2011, 09:10 PM
  3. error message
    By tri.yudhanto in forum JDBC
    Replies: 0
    Last Post: 01-13-2011, 01:20 PM
  4. Error Message????
    By Cubba27 in forum New To Java
    Replies: 11
    Last Post: 11-21-2009, 02:46 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
  •