Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Incompatible types

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Incompatible types

    In the method addNoDuplicateSources, the if statement has an error message - incompatible types.
    The input parameter to the method is a string and the return parameter from the getSource() method
    is a String. Why would the if statement give an incompatible types message.?

    import java.util.*;
    public class AnotherWord
    {
        private String word;
        private Vector<String> sourceList;
        private int count;
     
        public AnotherWord( String word, String source )
        {
            this.word = word.toLowerCase();
            count = 1;
            sourceList = new Vector<String> (3,2);
            sourceList.add( (String) source );
        }
     
        public void addNoDuplicateSources( String sourceToAdd)
        {
            boolean found = false;
            for (int i = 0; i <= sourceList.size(); i++)
            {
                if ( getSource(i).compareToIgnoreCase(sourceToAdd) ) { found = true; }
            }
            if (!found) { sourceList.add( sourceToAdd ); }
        }
     
        public String getSource(int index) 
        { 
            String result = null;
            if (index >=0 && index < sourceList.size()) { result = sourceList.get(index); }
            return result;
        }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,912
    Thanks
    55
    Thanked 2,351 Times in 2,322 Posts

    Default Re: Incompatible types

    Please copy and post here the full text of the error message so we can see it.

    Why would the if statement give an incompatible types message.?
    The if statement requires a boolean expression inside of its ()s.
    Does the code inside of the ()s return a boolean value?
    Read the API doc to see what the method returns.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    14
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default Re: Incompatible types

    problem is... compareToIgnoreCase() method returns "int" not "boolean"

  4. #4
    Junior Member
    Join Date
    Oct 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Incompatible types

    Using BlueJ --- the error message is simpy incompatible types

    and the variable sourceToAdd is highlighted in the if statement.

    tried to copy and paste, BlueJ wouldn't let me

    --- Update ---

    Using BlueJ --- the error message is simpy incompatible types

    and the variable sourceToAdd is highlighted in the if statement.

    tried to copy and paste, BlueJ wouldn't let me

  5. #5
    Junior Member
    Join Date
    Oct 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Incompatible types

    duh sorry for bothering you

    --- Update ---

    duh sorry for bothering you

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,912
    Thanks
    55
    Thanked 2,351 Times in 2,322 Posts

    Default Re: Incompatible types

    Do you understand the problem now?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Incompatible types
    By jadeclan in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 26th, 2012, 07:09 AM
  2. incompatible types!!
    By sneha343 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 30th, 2011, 05:48 PM
  3. incompatible types
    By frozen java in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 25th, 2011, 10:40 AM
  4. incompatible types Exception
    By world.java in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 17th, 2010, 01:33 PM
  5. Incompatible Types
    By Kimimaru in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 28th, 2010, 10:52 AM