android - Java - array of object - setting index of one sets entire array -


i lost @ point. simple but..... shrunk down code. don't believe removed relevant. appears works fine except 1 big flaw. when call setwhosonline, no matter index is, seems set entire array.

my watch environment window before setwhosonline call.

    users[0].name = null     users[1].name = null     users[2].name = null     users[3].name = null     etc.... 

i call

    setwhosonline("john",1); 

im expecting see...

    users[0].name = null     users[1].name = john     users[2].name = null     users[3].name = null 

unfortunately - i'm getting is...

    users[0].name = john     users[1].name = john     users[2].name = john     users[3].name = john 

my hair turning grey! hope has answer out there me....

class 1

public class login extends activity { public static who[] users = new who[100]; }  private static void setwhosonline(string user, int index) {       users[index].setname(user); }   } 

class 2

public class   { private static boolean active; private static boolean online; private static string msg=""; private static int msgcnt=0; private static string name; private static string ip; private static date stamp=new date();   public void init(int index) {       this.active = false;       this.online = false;       this.name = "";       this.ip = "";       this.stamp = new date(); }  //user      public final void setname(string value) {     this.name = value; } 

all fields in class static, hence instances of class share same data (i.e. have same name, same ip, etc.). using static in context not make sense.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -