简体   繁体   中英

Cannot find symbol error (calling a method)

The error i have is

Error:cannot find symbol
  symbol:  variable compareTo
  location:variable tim of type Time

The code where the error happens is

public String difference(Time tim)
{
      if(tim.compareTo==1)
{
      tim.minute = 0;
}
      //other code
}

and my compareTo is

public int compareTo(Object other)
{
    if (((Time)other).getHour()<hour)
    {
     return 1;
    }
 //and other code that repeat for return -1 and 0
}

Your syntax for calling the compareTo method is wrong. Without parentheses () , Java interprets it as a class variable. Try

if (compareTo(tim) == 1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM