The Artima Developer Community
Sponsored Link

Java Answers Forum
Arraylist catastrophe

1 reply on 1 page. Most recent reply: Nov 24, 2002 7:06 AM by Don Hill

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Nick

Posts: 1
Nickname: unclerory
Registered: Nov, 2002

Arraylist catastrophe Posted: Nov 23, 2002 3:46 PM
Reply to this message Reply
Advertisement
Help! Help!

I know how to place objects into an arraylist ie

myArrayList.add(new myObject());

but when I try to use these objects and their methods I fall over. What am I doing wrong.
The way I have tried doing it is thus:

myArrayList.get(1).myObjectsMethod()

Why does it not work?

any help would be appreciated
Nick


Don Hill

Posts: 70
Nickname: ssswdon
Registered: Jul, 2002

Re: Arraylist catastrophe Posted: Nov 24, 2002 7:06 AM
Reply to this message Reply
When dealing with arraylist you should use the iterator or turn to a array. I think you could do what you are but how does a Object ( this is what is returned by the get()) know of your method, you need to cast to your class type.

like
((myObject)myArrayList.get(1)).myObjectsMethod()

HTH

> Help! Help!
>
> I know how to place objects into an arraylist ie
>
> myArrayList.add(new myObject());
>
> but when I try to use these objects and their methods I
> fall over. What am I doing wrong.
> The way I have tried doing it is thus:
>
> myArrayList.get(1).myObjectsMethod()
>
> Why does it not work?
>
> any help would be appreciated
> Nick

Flat View: This topic has 1 reply on 1 page
Topic: Need Help Please Previous Topic   Next Topic Topic: help!: a loop problem

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use