Results 1 to 4 of 4
  1. #1
    Peril is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Default Stuck on an error

    Java Code:
    	public int findIndex(Competition x)
    	{
    	 int count = 0;
    	 	for(CompetitionNode current = head; current != null; current = current.next)
    		{
    	
              	if (current.c.getCompetitionName().compareTo(x) == 0) 
              	{
                   return count;
              	}
         	count ++;
    	 	}
    	}
    :confused: I get the following error: java:210: compareTo(java.lang.String) in java.lang.String cannot be applied to (Competition)

  2. #2
    Peril is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Default

    Nevermind, solved.

  3. #3
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    I have to do some guessing here, because you've only shared a bit of your code. (But thank you for using CODE tags properly!)

    I take it the "c" member variable of a CompetitionNode object is of type Competition? In any case, its getCompetitionName() method returns a String (which seems reasonable). You are trying to compare that String to a Competition named x. Maybe you mean to do this?
    Java Code:
              	if (current.c.getCompetitionName().compareTo(x.getCompetitionName()) == 0)
    And maybe this would be even more straightforward for you?
    Java Code:
              	if (current.c.getCompetitionName().equals(x.getCompetitionName()))
    -Gary-

  4. #4
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    Quote Originally Posted by Peril View Post
    Nevermind, solved.
    Glad you found it.

    -Gary-

Similar Threads

  1. Stuck in sea
    By programmer_007 in forum JDBC
    Replies: 1
    Last Post: 09-17-2009, 05:00 AM
  2. stuck on same syntax error....
    By Moltisanti in forum New To Java
    Replies: 2
    Last Post: 09-01-2009, 05:26 AM
  3. Im on my last lab!!!! And im stuck...:(
    By clanboru15 in forum New To Java
    Replies: 5
    Last Post: 03-13-2009, 02:44 AM
  4. really stuck now..
    By shongo in forum Advanced Java
    Replies: 2
    Last Post: 11-09-2008, 03:56 AM
  5. Stuck in need of help!
    By Zombie_Leg! in forum New To Java
    Replies: 1
    Last Post: 09-23-2008, 03:22 AM

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
  •