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 2 of 2

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;
        }
    }


    --- Update ---

    Ignore this post


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Incompatible types

    I would suggest you to read the syntax for if statement.

    Also, do you know, what this function String.compareToIgnoreCase(String) returns?
    Anyone who stops learning is old, whether at twenty or eighty. Anyone who keeps learning stays young. The greatest thing in life is to keep your mind young.

    - Henry Ford

Similar Threads

  1. Incompatible Types using DOMParser getDocument
    By steven0712 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: November 6th, 2012, 04:21 PM
  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, 09:52 AM