Page 2 of 2 FirstFirst 12
Results 21 to 40 of 40
  1. #21
    ralf is offline Member
    Join Date
    Jul 2011
    Posts
    98
    Rep Power
    0

    Default

    I am sorry that I bother you
    are you meaning a for loop? where should I implement it?

  2. #22
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    where should I implement it?
    At the location in your code where you want
    to print out the lot which has not been sold

  3. #23
    ralf is offline Member
    Join Date
    Jul 2011
    Posts
    98
    Rep Power
    0

    Default

    This don't work
    Java Code:
    for(Iterator i = lot.iterator(); i.hasNext());

  4. #24
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Where did that come from? Looking back at post#3 you used to know how to use an Iterator.

  5. #25
    ralf is offline Member
    Join Date
    Jul 2011
    Posts
    98
    Rep Power
    0

    Default

    I just found an example on the internet.
    but any tips on what the correct code would be?

  6. #26
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Did you try what you used in post#3?

    Can you list the programming steps necessary to do what you want to do?

  7. #27
    ralf is offline Member
    Join Date
    Jul 2011
    Posts
    98
    Rep Power
    0

    Default

    Yes, I tryed what I used in post 3. It did't work
    No, I don't now actually what to do now
    I have iterated through the arraylist and find the name and the value of the bid
    and now I must loop through it again to find the unsold item in the arraylist. But I can't figure it out how to implement the foor loop in a correct way to get the items which have not been given any value(not bid on)

  8. #28
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    I can't figure it out how to implement the foor loop in a correct way to get the items which
    Inside the loop, Use an if statement to select the items you want to process.
    Ignore all the others.

  9. #29
    ralf is offline Member
    Join Date
    Jul 2011
    Posts
    98
    Rep Power
    0

    Default

    Hello I have tryed to add an if test in different places, but I always get this error:
    java.lang.NullPointerException
    at Auction.close(Auction.java:113)
    java.lang.NullPointerException
    at Auction.close(Auction.java:113)
    I don't understand where I should include the second if test?
    Java Code:
           public void close()
            {
            Iterator it = lots.iterator();
            while(it.hasNext()) 
              {                        
                  Lot lot = (Lot) it.next(); //number, description, gethighestbid
                     if(lot != null)
                    {
                       //System.out.println(lot.toString());
                        System.out.println("Winner bid: " + lot.getHighestBid().getValue() + ": " + "The bidder: " + lot.getHighestBid().getBidder().getName());
                        }
                    else{
                        if(lot == null)
                        {
                         System.out.println("These lot have not get any bid: " + lot);   
                        }
                     }
                  } 
               }

  10. #30
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Java Code:
         if(lot != null)
                    {
      ...
    else{
                        if(lot == null)
    The second if test is redundant. Since lot will be either null or not null, there are no other choices. So if it is one it is not the other.

    NullPointerException
    at Auction.close(Auction.java:113)
    Look at line 113 and see what variable is null. If you can't see which variable (maybe more than one) print out the values of all the variables to find the null one. Then backtrack in your code to find out why it is null.
    Last edited by Norm; 07-06-2011 at 03:42 PM.

  11. #31
    ralf is offline Member
    Join Date
    Jul 2011
    Posts
    98
    Rep Power
    0

    Default

    Yes, I can see that this is redundant, but when I try to write out info from the method close when there are lots with no bid on the loop always end in the line below, so the else is never reached. any idea?
    Java Code:
    System.out.println("Winner bid: " + lot.getHighestBid().getValue() + ": " + "The bidder: " + lot.getHighestBid().getBidder().getName());
    and this is the line which gives the nullpoint code

  12. #32
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    when I try to write out info from the method close when there are lots with no bid on the loop always end in the line below
    Sorry, that doesn't make any sense to me. Did you leave out any . or , or ; so that it would make sense?

    Have you found the variable that is null yet?
    What printed out when you added a println statements to print all the variables used in the line with problem?

    For example:
    ...println("lot=" + lot);
    ...println("lot.getHighestBid=" + lot.getHighestBid());

  13. #33
    ralf is offline Member
    Join Date
    Jul 2011
    Posts
    98
    Rep Power
    0

    Default

    Hello,

    Here is the output:
    Java Code:
     I don't think I left anything behind.
    lot=1: f    (No bid)
    lot.getHighestBid=null     since there has not been bid anything on that lot the getHighestBid() is null, when I add getValue() behind getHighestBid() then the nullpoint occur
    lot=2: t    (No bid)
    lot.getHighestBid=null

  14. #34
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Your printlns show that the getHighestBid() method returns null. So you can't use the reference it returns to call the getValue() method.
    That would cause the NullPointerException.

    You must test the value returned before you use it to call getValue().

  15. #35
    ralf is offline Member
    Join Date
    Jul 2011
    Posts
    98
    Rep Power
    0

    Default

    The output now:
    Java Code:
    These lot have not get any bid: 1: Hat    (No bid)
    Winner bid: 400: The bidder: Harry
    These lot have not get any bid: 3: Table    (No bid)
    
        if(lot.getHighestBid() != null)
                    {
                       //System.out.println(lot.toString());
                       //System.out.println("lot=" + lot);
                      // System.out.println("lot.getHighestBid=" + lot.getHighestBid());
                      // System.out.println(lot.getNumber());
    
    
                        System.out.println("Winner bid: " + lot.getHighestBid().getValue() + ": " + "The bidder: " + lot.getHighestBid().getBidder().getName());
                        }
                       else {
                        if(lot.getHighestBid() == null)  //The output seems correct, although the if test is still redundant, How to write the if test correct?
                        {
                         System.out.println("These lot have not get any bid: " + lot);

  16. #36
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Sorry, I don't see where you put the output. The only thing I see is some code.

  17. #37
    ralf is offline Member
    Join Date
    Jul 2011
    Posts
    98
    Rep Power
    0

    Default

    The output:
    These lot have not get any bid: 1: Hat (No bid)
    Winner bid: 400: The bidder: Harry
    These lot have not get any bid: 3: Table (No bid)

  18. #38
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Is that good output now?

  19. #39
    ralf is offline Member
    Join Date
    Jul 2011
    Posts
    98
    Rep Power
    0

    Default

    It print out which lot that has been sold and which has not been sold. I think that is correct. Don't you?
    Thanks for your help again!

  20. #40
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    It print out which lot that has been sold and which has not been sold. I think that is correct. Don't you?
    It could be. I don't know what your requirements are.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 2
    Last Post: 04-28-2011, 11:25 AM
  2. Replies: 1
    Last Post: 04-14-2011, 01:48 PM
  3. Problem with keeping values into an arrayList
    By Daniel Silvester in forum New To Java
    Replies: 0
    Last Post: 12-02-2009, 01:14 AM
  4. Replies: 5
    Last Post: 07-28-2009, 10:22 PM
  5. trying to set() values of in list of arraylist
    By alvations in forum New To Java
    Replies: 15
    Last Post: 10-13-2008, 09:35 PM

Posting Permissions

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