This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes stuck with this array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "stuck with this array" Watch "stuck with this array" New topic
Author

stuck with this array

Cougar Vis
Greenhorn

Joined: May 12, 2004
Posts: 19
coded this but for somereason it wont let me add a string into it, or do i need a different type of array?


[ November 28, 2004: Message edited by: Cougar Vis ]
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272


You have to match a method signature:
public boolean add(Object o)
or
public void add(int index, Object element)

try this:
exits.add( "north" );
exits.add( "west" );

By the way,what are you doing with the formal parameter "theExits"?


Mike Gershman
SCJP 1.4, SCWCD in process
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

the add method takes 1 parameter (well, there are versions that take ore than one, but none that takes two strings....)

What you need to do is break up the adding of things into the list into two separate commands:


Also, I would just declare the exits to be a List; this hids that fact that it is an array list and lets you replace it with any type of list later one (like a LinkedList). Not that that is likely to happen here, but it is a good habit to get into.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: stuck with this array
 
Similar Threads
ArrayList.get incompatible type
final modifier in variable
final local variable question
filing an array with the output from a method
simple J2EE question