Results 1 to 7 of 7
  1. #1
    nidhirastogi is offline Member
    Join Date
    Jul 2008
    Posts
    16
    Rep Power
    0

    Default Vector getting re-created with each call

    Hi All
    I have created a Vector which uses Random Number Generator to create values.
    The method that is created to generate this vector is being called in multiple files.
    So definitely the vector is running the random number generator each it is called in each file.
    I only need one consistent set of vector values, but cant' understand how to achieve that.
    Can someone throw some light on this please.
    Thanks a lot
    -Nidhi

  2. #2
    nidhirastogi is offline Member
    Join Date
    Jul 2008
    Posts
    16
    Rep Power
    0

    Default

    I just made the vector static. The problem is now solved.

  3. #3
    georgemc is offline Senior Member
    Join Date
    Sep 2008
    Posts
    135
    Rep Power
    0

    Default

    Quote Originally Posted by nidhirastogi View Post
    I just made the vector static. The problem is now solved.
    You haven't, really. You've just stuck a band-aid over the symptom

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by georgemc View Post
    You haven't, really. You've just stuck a band-aid over the symptom
    At least it stopped the bleeding (and the bleating). ;-)

  5. #5
    nidhirastogi is offline Member
    Join Date
    Jul 2008
    Posts
    16
    Rep Power
    0

    Default

    Quote Originally Posted by georgemc View Post
    You haven't, really. You've just stuck a band-aid over the symptom
    Any suggestions over how to treat it from the root :)

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

    Default

    If you only want one instance of your class, then look at the Singleton pattern (it uses static). That will help you to have only one instance of the class used by all your other classes.

  7. #7
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by nidhirastogi View Post
    Any suggestions over how to treat it from the root :)
    Maybe, if you were to show what you started with and explain a little better what the actual problem was. Your description gave no information on which anybody could really work.

Similar Threads

  1. Calling a method on original class from created class
    By kpedersen in forum Advanced Java
    Replies: 4
    Last Post: 08-20-2008, 12:25 AM
  2. How to find file created date.....
    By roshithmca in forum Advanced Java
    Replies: 1
    Last Post: 02-18-2008, 09:48 AM
  3. Help, created a username and password box
    By cachi in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 04:21 AM
  4. create a tree when a new class is created
    By osval in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 08:58 PM
  5. Replies: 4
    Last Post: 06-05-2007, 01:45 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
  •