ArrayList Overwriting old elements when adding new
From: Apollyon (abbadon_at_loopback.edu)
Date: 04/26/04
- Next message: Apollyon: "Re: ArrayList Overwriting old elements when adding new"
- Previous message: Sam P: "org.apache.jasper.JasperException"
- Next in thread: Apollyon: "Re: ArrayList Overwriting old elements when adding new"
- Reply: Apollyon: "Re: ArrayList Overwriting old elements when adding new"
- Reply: Bjorn Abelli: "Re: ArrayList Overwriting old elements when adding new"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 25 Apr 2004 22:56:21 -0600
I'm having a problem setting up an ArrayList ...
For reference, I'm making a very simply very basic IM type client.
I have a class called ChatWindow which is obviously the window that
you type into.
I'm trying to keep track of these windows via an ArrayList because it
seemed simple. When I create the first window(name "first") it works.
When I create the second window(named "second") it seems to overwrite
the first one. ID is 0 when the first window is created and 1 when the
second window is created.
get_name() returns a string that contains then ame that the ChatWindow
was originally created with.
I'm not certain if it's just some error in my logic or what, but I
can't figure out why, when I give it the second window and it creates
it returns
"at ID 0second"
"at ID 1second"
As you can see the object it's returning is the second window for both
elements in the list.
Am I doing something wrong, or just approaching this the wrong way?
public void createChatWindow (final int ID, String uName){
ChatWindow tempWindow = new ChatWindow(uName);
windowArrayList.add(tempWindow);
if (ID > 0)
{
ChatWindow tempWindow2 = (ChatWindow)windowArrayList.get(0);
System.out.println("at ID 0" + tempWindow2.get_name());
ChatWindow tempWindow3 = (ChatWindow)windowArrayList.get(1);
System.out.println("at ID 1" + tempWindow3.get_name());
}
}
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
- Next message: Apollyon: "Re: ArrayList Overwriting old elements when adding new"
- Previous message: Sam P: "org.apache.jasper.JasperException"
- Next in thread: Apollyon: "Re: ArrayList Overwriting old elements when adding new"
- Reply: Apollyon: "Re: ArrayList Overwriting old elements when adding new"
- Reply: Bjorn Abelli: "Re: ArrayList Overwriting old elements when adding new"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]