Results 1 to 7 of 7
  1. #1
    shadowblade19 is offline Member
    Join Date
    Sep 2008
    Posts
    4
    Rep Power
    0

    Default [SOLVED] boolean method problem

    Edited by user.
    Last edited by shadowblade19; 12-03-2008 at 07:29 PM.

  2. #2
    racerxadam is offline Member
    Join Date
    Jul 2008
    Posts
    68
    Rep Power
    0

    Default

    can you post the actual stack trace, and possibly more of the code? Where is the ArrayList membersList declared?

  3. #3
    shadowblade19 is offline Member
    Join Date
    Sep 2008
    Posts
    4
    Rep Power
    0

    Default

    Edited by user
    Last edited by shadowblade19; 12-03-2008 at 07:29 PM.

  4. #4
    racerxadam is offline Member
    Join Date
    Jul 2008
    Posts
    68
    Rep Power
    0

    Default

    The problem is your generic type in the method declaration doesn't match the declaration of the ArrayList you are passing. You've declared membersList as:

    Java Code:
    public static ArrayList <Member> membersList = new ArrayList <Member>();
    and then pass it to the method declared as:

    Java Code:
     public boolean loanExistsUndergrad(int studID, ArrayList <UndergradMember> undergradList){
    from the declaration of the list, there is no way to guarantee that the list only contains UndergradMember objects.

    Java Code:
    public boolean loanExistsUndergrad(int studID, ArrayList <Member> undergradList){
    should fix it. you can then get items out of the list and cast them to UndergradMember objects like this:

    Java Code:
    UndergradMember undergradMember = (UndergradMember)undergradList.get( i );

  5. #5
    shadowblade19 is offline Member
    Join Date
    Sep 2008
    Posts
    4
    Rep Power
    0

    Default

    Where do I place UndergradMember undergradMember = (UndergradMember)undergradList.get( i ); ? Is this inside loanExistsUndergrad?

  6. #6
    racerxadam is offline Member
    Join Date
    Jul 2008
    Posts
    68
    Rep Power
    0

    Default

    yes, it will be inside of your method. You won't be able to refer directly to the undergradList.get(i).returnStudID() because the list is of Member objects not UndergradMember objects which the returnStudID method is valid for. So get the object out of the list and cast it to an UndergradMember object, then call returnStudID and do your check on the result.

  7. #7
    shadowblade19 is offline Member
    Join Date
    Sep 2008
    Posts
    4
    Rep Power
    0

    Default

    Edited by user.
    Last edited by shadowblade19; 12-03-2008 at 07:30 PM.

Similar Threads

  1. [SOLVED] Boolean Expression Evaluation Framework
    By priyanka.dandekar in forum Advanced Java
    Replies: 8
    Last Post: 03-27-2010, 02:35 PM
  2. Replies: 29
    Last Post: 09-25-2008, 07:55 PM
  3. boolean to string
    By otoro_java in forum New To Java
    Replies: 2
    Last Post: 01-30-2008, 05:31 AM
  4. boolean variables
    By ravian in forum New To Java
    Replies: 3
    Last Post: 12-31-2007, 04:58 AM
  5. Boolean Expression
    By ritwik07 in forum New To Java
    Replies: 3
    Last Post: 07-11-2007, 04:11 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
  •