By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,723 Members | 1,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,723 IT Pros & Developers. It's quick & easy.

Cannot find symbol error???? Please Advice!

P: 2
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\aa1\test.java:122: cannot find symbol
symbol : method objCompare(java.lang.Object,Person)
location: class test
if (objCompare(inputArr.get(i), p1) == 0)
^
C:\Documents and Settings\wei cheng\Desktop\aa1\test.java:130: cannot find symbol
symbol : method objCompare(java.lang.Object,Person)
location: class test
if (objCompare(inputArr.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.println("***************binary Search******************");
int result = LibraryComparator.binarySearch(inputArr, p1, new objCompare());
System.out.println(surName + " " + result);
if (result != -1)
{
GenericSimpleArrayList outputArr = new GenericSimpleArrayList();

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

public static class objCompare<AnyType extends Comparable<? super AnyType>> implements Comparator<Person>
{
public int compare(Person lhs, Person rhs)
{
return lhs.surName.toLowerCase().compareTo (rhs.surName.toLowerCase());
}
}
Aug 24 '07 #1
Share this Question
Share on Google+
4 Replies


Expert 10K+
P: 11,448
objCompare is a class; you cannot invoke it as if it were a method.

kind regards,

Jos
Aug 24 '07 #2

P: 2
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<AnyType extends Comparable<? super AnyType>> implements Comparator<Person>
{
public int compare(Person lhs, Person rhs)
{
return lhs.surName.toLowerCase().compareTo (rhs.surName.toLowerCase());
}
}
Aug 25 '07 #3

P: 4
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\aa1\test.java:122: cannot find symbol
symbol : method objCompare(java.lang.Object,Person)
location: class test
if (objCompare(inputArr.get(i), p1) == 0)
^
C:\Documents and Settings\wei cheng\Desktop\aa1\test.java:130: cannot find symbol
symbol : method objCompare(java.lang.Object,Person)
location: class test
if (objCompare(inputArr.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.println("***************binary Search******************");
int result = LibraryComparator.binarySearch(inputArr, p1, new objCompare());
System.out.println(surName + " " + result);
if (result != -1)
{
GenericSimpleArrayList outputArr = new GenericSimpleArrayList();

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

public static class objCompare<AnyType extends Comparable<? super AnyType>> implements Comparator<Person>
{
public int compare(Person lhs, Person rhs)
{
return lhs.surName.toLowerCase().compareTo (rhs.surName.toLowerCase());
}
}








Hi
Their is no Predefined method objCompare() in java.So where is the implementation for this method...
Aug 25 '07 #4

Nepomuk
Expert 2.5K+
P: 3,112
Try this:
Expand|Select|Wrap|Line Numbers
  1. StringTokenizer st = new StringTokenizer(surName);
  2. surName = st.nextToken();
  3. Person p1 = new Person(surName, "", 0);
  4.  
  5.  // do the search search
  6. System.out.println("***************binary Search******************");
  7. int result = LibraryComparator.binarySearch(inputArr, p1, new objCompare());
  8.  System.out.println(surName + " " + result);
  9. if (result != -1)
  10. {
  11.      GenericSimpleArrayList outputArr = new GenericSimpleArrayList();
  12.  
  13. //search 1st element of input array that matches
  14.                  for (int i=result; i>=0; i--)
  15.     {
  16.          if (new objCompare<...>.compare(inputArr.get(i), p1) == 0)                       {                            
  17.                             outputArr.add(inputArr.get(i));
  18.                      }
  19.                 }
  20.                 //search for other element of input array that matches
  21.     for (int i=result+1; i<inputArr.size(); i++) 
  22.                 {
  23.                         if (new objCompare<...>.compare(inputArr.get(i), p1) == 0)                          {
  24.                             outputArr.add(inputArr.get(i));
  25.                         }
  26.                     }
  27.  
  28. public static class objCompare<AnyType extends Comparable<? super AnyType>> implements Comparator<Person>
  29.     {
  30.          public int compare(Person lhs, Person rhs)
  31.          {
  32.             return lhs.surName.toLowerCase().compareTo (rhs.surName.toLowerCase());
  33.           }
  34.      }
  35.  
(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.compare(...,...).
Aug 25 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.