Cannot find symbol error???? Please Advice!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jingchua
    New Member
    • Aug 2007
    • 2

    Cannot find symbol error???? Please Advice!

    Hi,
    can anyone help out here????
    I have the below error after compling the file. Any idea what is wrong in the declaration that was done in the above code??? Appreciate any help on shedding some light for this error on how to rectify it.
    C:\Documents and Settings\wei cheng\Desktop\a a1\test.java:12 2: cannot find symbol
    symbol : method objCompare(java .lang.Object,Pe rson)
    location: class test
    if (objCompare(inp utArr.get(i), p1) == 0)
    ^
    C:\Documents and Settings\wei cheng\Desktop\a a1\test.java:13 0: cannot find symbol
    symbol : method objCompare(java .lang.Object,Pe rson)
    location: class test
    if (objCompare(inp utArr.get(i), p1) == 0)



    This is the source code and for your info they are all in the same file:

    StringTokenizer st = new StringTokenizer (surName);
    surName = st.nextToken();
    Person p1 = new Person(surName, "", 0);


    // do the search search
    System.out.prin tln("********** *****binary Search********* *********");
    int result = LibraryComparat or.binarySearch (inputArr, p1, new objCompare());
    System.out.prin tln(surName + " " + result);
    if (result != -1)
    {
    GenericSimpleAr rayList outputArr = new GenericSimpleAr rayList();

    //search 1st element of input array that matches
    for (int i=result; i>=0; i--)
    {
    if (objCompare(inp utArr.get(i), p1) == 0) {
    outputArr.add(i nputArr.get(i)) ;
    }
    }
    //search for other element of input array that matches
    for (int i=result+1; i<inputArr.size (); i++)
    {
    if (objCompare(inp utArr.get(i), p1) == 0) {
    outputArr.add(i nputArr.get(i)) ;
    }
    }

    public static class objCompare<AnyT ype extends Comparable<? super AnyType>> implements Comparator<Pers on>
    {
    public int compare(Person lhs, Person rhs)
    {
    return lhs.surName.toL owerCase().comp areTo (rhs.surName.to LowerCase());
    }
    }
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    objCompare is a class; you cannot invoke it as if it were a method.

    kind regards,

    Jos

    Comment

    • jingchua
      New Member
      • Aug 2007
      • 2

      #3
      Hi Jos,

      Thanks for the reply. But can u point out to me on how to rectify this problem. Not too sure how to do it.

      I had thought this code below was going to be helpful but i cant figure out how to use it correctly.

      public static class objCompare<AnyT ype extends Comparable<? super AnyType>> implements Comparator<Pers on>
      {
      public int compare(Person lhs, Person rhs)
      {
      return lhs.surName.toL owerCase().comp areTo (rhs.surName.to LowerCase());
      }
      }

      Comment

      • praveenm237
        New Member
        • Nov 2006
        • 4

        #4
        Originally posted by jingchua
        Hi,
        can anyone help out here????
        I have the below error after compling the file. Any idea what is wrong in the declaration that was done in the above code??? Appreciate any help on shedding some light for this error on how to rectify it.
        C:\Documents and Settings\wei cheng\Desktop\a a1\test.java:12 2: cannot find symbol
        symbol : method objCompare(java .lang.Object,Pe rson)
        location: class test
        if (objCompare(inp utArr.get(i), p1) == 0)
        ^
        C:\Documents and Settings\wei cheng\Desktop\a a1\test.java:13 0: cannot find symbol
        symbol : method objCompare(java .lang.Object,Pe rson)
        location: class test
        if (objCompare(inp utArr.get(i), p1) == 0)



        This is the source code and for your info they are all in the same file:

        StringTokenizer st = new StringTokenizer (surName);
        surName = st.nextToken();
        Person p1 = new Person(surName, "", 0);


        // do the search search
        System.out.prin tln("********** *****binary Search********* *********");
        int result = LibraryComparat or.binarySearch (inputArr, p1, new objCompare());
        System.out.prin tln(surName + " " + result);
        if (result != -1)
        {
        GenericSimpleAr rayList outputArr = new GenericSimpleAr rayList();

        //search 1st element of input array that matches
        for (int i=result; i>=0; i--)
        {
        if (objCompare(inp utArr.get(i), p1) == 0) {
        outputArr.add(i nputArr.get(i)) ;
        }
        }
        //search for other element of input array that matches
        for (int i=result+1; i<inputArr.size (); i++)
        {
        if (objCompare(inp utArr.get(i), p1) == 0) {
        outputArr.add(i nputArr.get(i)) ;
        }
        }

        public static class objCompare<AnyT ype extends Comparable<? super AnyType>> implements Comparator<Pers on>
        {
        public int compare(Person lhs, Person rhs)
        {
        return lhs.surName.toL owerCase().comp areTo (rhs.surName.to LowerCase());
        }
        }








        Hi
        Their is no Predefined method objCompare() in java.So where is the implementation for this method...

        Comment

        • Nepomuk
          Recognized Expert Specialist
          • Aug 2007
          • 3111

          #5
          Try this:
          [CODE=java]
          StringTokenizer st = new StringTokenizer (surName);
          surName = st.nextToken();
          Person p1 = new Person(surName, "", 0);

          // do the search search
          System.out.prin tln("********** *****binary Search********* *********");
          int result = LibraryComparat or.binarySearch (inputArr, p1, new objCompare());
          System.out.prin tln(surName + " " + result);
          if (result != -1)
          {
          GenericSimpleAr rayList outputArr = new GenericSimpleAr rayList();

          //search 1st element of input array that matches
          for (int i=result; i>=0; i--)
          {
          if (new objCompare<...> .compare(inputA rr.get(i), p1) == 0) {
          outputArr.add(i nputArr.get(i)) ;
          }
          }
          //search for other element of input array that matches
          for (int i=result+1; i<inputArr.size (); i++)
          {
          if (new objCompare<...> .compare(inputA rr.get(i), p1) == 0) {
          outputArr.add(i nputArr.get(i)) ;
          }
          }

          public static class objCompare<AnyT ype extends Comparable<? super AnyType>> implements Comparator<Pers on>
          {
          public int compare(Person lhs, Person rhs)
          {
          return lhs.surName.toL owerCase().comp areTo (rhs.surName.to LowerCase());
          }
          }
          [/CODE](Note the changes in Line 16 and 23!)
          An alternative would be, to create one objCompare (objCompare compareObj = new objCompare<...> ()) before using it and then just write compareObj.comp are(...,...).

          Comment

          Working...