Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By Fubarable

Thread: incompatible types?

  1. #1
    slider57 is offline Member
    Join Date
    Aug 2011
    Posts
    29
    Rep Power
    0

    Default incompatible types?

    My array that was initialized to hold a Persons class will not hold the class.
    I am seriously confused why this is happening.

    these are the lines of code that hate me:
    array[0] = p.setPerson(null, new Person(), st1);
    array[i] = p.setPerson(array[i - 1], new Person(), st1);
    They are on line 12 and 20.

    Java Code:
      public void run()
       {
          // parse the data into Person objects and display it
          Person p = new Person();
          StringTokenizer st = new StringTokenizer(mData, DEFAULT_RECORD_SEPARATOR);
          StringTokenizer st1 = new StringTokenizer(st.nextToken(),
                                                    DEFAULT_FIELD_SEPARATOR);
          Person[] array;
          array = new Person[10];
          int startVerse = DEFAULT_STARTVERSE;
          
          array[0] = p.setPerson(null, new Person(), st1);   
          out.println(cFormat.format(p.toArray(startVerse)));
      
          for(int i = 1; st.hasMoreTokens(); i++)
          {
             p = new Person();
             startVerse = startVerse + 3;
             st1 = new StringTokenizer(st.nextToken(), DEFAULT_FIELD_SEPARATOR);
             array[i] = p.setPerson(array[i - 1], new Person(), st1);
             //out.println(cFormat.format(p.toArray(startVerse)));
          }
          
       }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: incompatible types?

    Quote Originally Posted by slider57 View Post
    My array that was initialized to hold a Persons class will not hold the class.
    I am seriously confused why this is happening.

    these are the lines of code that hate me:
    array[0] = p.setPerson(null, new Person(), st1);
    array[i] = p.setPerson(array[i - 1], new Person(), st1);
    They are on line 12 and 20.
    Where are your error messages as it is quite hard for us to guess what is wrong without this very important information?

    I will guess though. You aren't assigning a Person object to the array item but rather whatever is returned by the setPerson(...) method. What does this method return by the way?

  3. #3
    slider57 is offline Member
    Join Date
    Aug 2011
    Posts
    29
    Rep Power
    0

    Default Re: incompatible types?

    I really appreciate you writing back. I solved the issue as soon as I hit submit. I used a setter which doesnt return anything so thats why it hated me but ill remember to put up the error code next time

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Incompatible types
    By Yokomoko in forum New To Java
    Replies: 10
    Last Post: 07-10-2012, 04:49 AM
  2. incompatible types
    By angelicatomnob in forum New To Java
    Replies: 3
    Last Post: 01-17-2012, 04:25 PM
  3. incompatible types!!
    By sneha343 in forum New To Java
    Replies: 7
    Last Post: 12-01-2011, 12:49 AM
  4. incompatible types
    By effa in forum New To Java
    Replies: 16
    Last Post: 02-03-2011, 10:50 AM
  5. Incompatible types
    By bayan in forum New To Java
    Replies: 5
    Last Post: 11-04-2010, 09:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •