17 Replies - 600 Views - Last Post: 07 May 2011 - 12:17 PM
#1
How to add things to a class that is exending arraylist
Posted 06 May 2011 - 02:20 PM
I have a method in People class that reads in a file and creates an object. I want to add the object to my People ArrayList, but when i put People.add(object); it doesn't work. Am i suppose to make a constructor that creates an arraylist? I am very lost.
Replies To: How to add things to a class that is exending arraylist
#2
Re: How to add things to a class that is exending arraylist
Posted 06 May 2011 - 02:21 PM
#3
Re: How to add things to a class that is exending arraylist
Posted 06 May 2011 - 02:34 PM
#4
Re: How to add things to a class that is exending arraylist
Posted 06 May 2011 - 02:41 PM
but this is the error i get:
cannot make a static reference to the non-static method add(object) from the type arraylist.
this is when i try to do People.add(my_object).
Right now all i have is the method that adds the object, and i have a class for my_object which creates an object. That is all that I have, and I am trying to add my_object to my People ArrayList.
This post has been edited by paki123: 06 May 2011 - 03:04 PM
#5
Re: How to add things to a class that is exending arraylist
Posted 06 May 2011 - 03:09 PM
#6
Re: How to add things to a class that is exending arraylist
Posted 06 May 2011 - 03:23 PM
#7
Re: How to add things to a class that is exending arraylist
Posted 06 May 2011 - 03:33 PM
I am using .add method which is static, I think I am suppose to add my object in a non-static way... Is there a way to do this?
#8
Re: How to add things to a class that is exending arraylist
Posted 06 May 2011 - 03:37 PM
#9
Re: How to add things to a class that is exending arraylist
Posted 06 May 2011 - 03:39 PM
#10
Re: How to add things to a class that is exending arraylist
Posted 06 May 2011 - 03:41 PM
#11
Re: How to add things to a class that is exending arraylist
Posted 06 May 2011 - 03:46 PM
This post has been edited by paki123: 06 May 2011 - 04:00 PM
#12
Re: How to add things to a class that is exending arraylist
Posted 06 May 2011 - 03:51 PM
#13
Re: How to add things to a class that is exending arraylist
Posted 06 May 2011 - 03:54 PM
Renagado, on 06 May 2011 - 03:51 PM, said:
The problem is that when I do Server.add(mv) i get that message.
and there was an error, tehre should have been a new object in that section
This post has been edited by paki123: 06 May 2011 - 03:56 PM
#14
Re: How to add things to a class that is exending arraylist
Posted 06 May 2011 - 04:26 PM
Say i have a class called People which extends an ArrayList.
so
Code:
public class People extends ArrayList
Part of my assignment is to add a string that i get while using a method which reads code and instatiates string objects inside a while loop.
AFter I instatiate a string, I'm suppose to add it to the People ArrayList within the People class. How would i do this?
EDIT: NEVER MIND I GOT IT! you are suppose to do this.add(object);
This post has been edited by paki123: 06 May 2011 - 04:29 PM
#15
Re: How to add things to a class that is exending arraylist
Posted 06 May 2011 - 04:29 PM
|
|

New Topic/Question
This topic is locked




MultiQuote



|