Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 46
  1. #21
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default

    Quote Originally Posted by dlorde View Post
    No, he's starting with an array of size 0, so there can never be any items to copy:
    Sigh. Yes. But his original post was not all of the code. The method in question is what adds items to the array (by copying it to a new array). So yes, the size starts at 0. But that does not mean that nothing can be added to it. That's like saying nothing can be added to an ArrayList because its initial size is zero.

    I urge you to hesitate before posting when you have no idea what you're talking about. It just wastes everyone's time.


    Quote Originally Posted by dlorde View Post
    Java Code:
    private Person[] arr = new Person[0];
    What is that going to achieve?
    Once again, it initializes an empty array. He increases the size as he goes by copying it to a new array, then replacing this array with that one.

    If you don't understand what's going on, please don't try to offer help, or whatever it is you think you're doing by arguing these small points. Wait until you actually understand what's happening.

    This is why I asked the OP for an SSCCE.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  2. #22
    giorgi is offline Member
    Join Date
    Apr 2011
    Posts
    23
    Rep Power
    0

    Default

    what means OP for SSCCE

  3. #23
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Short, Self Contained, Correct (Compilable), Example.

    The smallest thing that shows your problem.

    The advantage of trying something like that is it often leads you to the anser before you even have to come here.

  4. #24
    giorgi is offline Member
    Join Date
    Apr 2011
    Posts
    23
    Rep Power
    0

    Default

    so.when i call "register" it adds only one object into array.and when i try to register another object arr size is still 0 and after adding there is only one member.i want it to save the added object and add another too.after all this when i want to print the members of the array it says there is 0 member.is it ok?understand?
    code:

    private Person[] arr = new Person[0];

    public void addPerson(Person newMan) {
    Person[] arr1 = new Person[arr.length + 1];
    for (int i = 0; i < arr.length; i++) {
    arr1[i] = arr[i];
    }// end for
    arr1[arr1.length - 1] = newMan;
    arr = arr1;
    }// end addPerson

  5. #25
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default

    Again, that's not an SSCCE. I think I'm going to start ignoring this thread soon.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #26
    giorgi is offline Member
    Join Date
    Apr 2011
    Posts
    23
    Rep Power
    0

    Default

    i can't explain my problem other way.sorry

  7. #27
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Java Code:
    while (true) {
        String input = scan.nextLine();
    
    [B]    PersonContainer per = new PersonContainer();[/B]
        if (input.equalsIgnoreCase("exit")) {
            System.out.println("Good Bye");
            break;
    
        } else if (input.equalsIgnoreCase("register")) {
            System.out.println("add person name and group No");
            String a = scan.nextLine();
            int b = Integer.parseInt(scan.nextLine());
            per.register(a, b);
            System.out.println("there is "+per.getLength()+" person");
    
        } else if (input.equalsIgnoreCase("print")) {
    
            System.out.println("name / Group No");
            per.printArr();
    
        } else if (input.equalsIgnoreCase("name search")) {
    
        }
        else if (input.equalsIgnoreCase("index search")){
    
        }
    }// end while
    Each time round your while loop you are creating a new PersonContainer, so you aren't actually adding to an existing container but to a new one.
    When you type "print" it creates a new container with nothing in it.

  8. #28
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Incredible vanishing posts!
    :)

    I'm guessing you figured it out...

  9. #29
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default

    I hope that the OP, after this little issue is solved, comes back here to tell us what the problem was because I really can't see the mistake in the code shown.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #30
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    The mistake is in the code above, summarised as:
    loop
    - create container
    - depending on user input, add to container or print container.
    end loop

    So when he's printing the container he's actually printing a brand new one.

  11. #31
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    Quote Originally Posted by KevinWorkman View Post
    If you don't understand what's going on, please don't try to offer help, or whatever it is you think you're doing by arguing these small points. Wait until you actually understand what's happening.
    I see now what was happening - I misread the code due to it's lack of formatting. My mistake.

    Don't take it so hard - sounds like you've had a long day.

  12. #32
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default

    Quote Originally Posted by dlorde View Post
    I see now what was happening - I misread the code due to it's lack of formatting. My mistake.

    Don't take it so hard - sounds like you've had a long day.
    Everyone else read the code fine.

    I'm not taking it hard, in fact, it took me a second to remember what you were talking about. It just gets annoying to have to deal with people who offer incorrect information that just confuses an already confused OP. I don't see why people insist on "helping" when they don't really know what's going on themselves.

    If this is an isolated mistake, fine, but there are a few repeat offenders. I'm not saying you're one of them.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  13. #33
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Tolls View Post
    The mistake is in the code above, summarised as:
    loop
    - create container
    - depending on user input, add to container or print container.
    end loop

    So when he's printing the container he's actually printing a brand new one.
    Thanks, I see the mistake now; I was still focusing on 'add a new longer array, copy elements over yadda, yadda'. I guess it's the old predator genes in me that make me focus on the wrong prey ;-) Also the lack of code formattting didn't help me (<--- I know, lame excuse, I know ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  14. #34
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    Quote Originally Posted by KevinWorkman View Post
    Everyone else read the code fine.
    I made a mistake - it happens.

    If this is an isolated mistake, fine, but there are a few repeat offenders. I'm not saying you're one of them.
    Hopefully not, but I can't promise not to make another mistake :D

  15. #35
    giorgi is offline Member
    Join Date
    Apr 2011
    Posts
    23
    Rep Power
    0

    Default

    thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx Tolls.now it is working.now i gonna write the methods that finds the member of the array

  16. #36
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by giorgi View Post
    thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx thanx Tolls.
    All monetary expressions of gratitude should be passed on to me so I can take care that it reaches its final destination; thank you for your cooperation ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  17. #37
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,196
    Rep Power
    19

    Default

    All monetary expressions of gratitude should be passed on to me
    PM me all your credit card numbers, along with your netbanking account details, usernames and passwords and I'll see that it's done.

    db <-- laughing all the way to the bank

  18. #38
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Quote Originally Posted by JosAH View Post
    Also the lack of code formattting didn't help me (<--- I know, lame excuse, I know ;-)

    kind regards,

    Jos
    Hey, that's my favourite excuse!
    :)

  19. #39
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Tolls View Post
    Hey, that's my favourite excuse!
    :)
    Never mind your lame excuses; did you receive the tokens of monetary thankfulness? If not, that darn Darryl must've kept them; bloody phisher! I suggest a head-first defenestration!

    kindest regards,

    Jos ;-)
    cenosillicaphobia: the fear for an empty beer glass

  20. #40
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    I would agree, but isn't it an awfully long way from Goa to Prague?

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Replies: 5
    Last Post: 01-05-2014, 09:12 PM
  2. increase pixel size
    By rosh72851 in forum New To Java
    Replies: 9
    Last Post: 07-31-2012, 07:30 PM
  3. Replies: 4
    Last Post: 01-18-2011, 08:22 AM
  4. Replies: 3
    Last Post: 09-27-2008, 04:46 AM
  5. gridbaglayout: increase/decrease size of components.
    By newtojava7 in forum New To Java
    Replies: 2
    Last Post: 01-28-2008, 07:22 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
  •