Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Extracting data elements from a user-defined class stored in an ArrayList



Joseph Broghamer wrote:

>Using the NetBeans debugger I was able to confirm that the data does exist
>in ArrayList element zero (0). However, when I try to extract a data
>element from the class with a the following statement:
>
> System.out.println (personArrayList.get(0).getFirstName());
>
> I get the 'cannot find symbol' error during compile.

Please copy and paste the exact error you you get into an email, and post
it to the list.  There can be any number of different symbols that aren't
being found, and what isn't found tells a lot about what's wrong.
Paraphrasing errors is vague; accuracy matters.

The following isolated test-case works for me.  If it doesn't compile or
run correctly for you, please copy and paste any errors you get into an
email, and post to the list.

If the following works, then I suggest making your own test-case from your
original code, perhaps by removing things until it works, then adding
things back until it breaks.


import java.util.*;

public class Lister
{
  public static void main( String[] args )
  {
    ArrayList <Person> personArrayList = new ArrayList<Person>();

    Person newPerson = new Person( "Arnold", "Rimmer" );

    personArrayList.add( newPerson );

    System.out.println( "Value for personArrayList.get(0) = " +
personArrayList.get(0) );
    System.out.println( personArrayList.get(0).getFirstName() );
  }
}

class Person
{
  private String first, last;

  public Person( String first, String last )
  {  this.first = first;  this.last = last;  }

  public String getFirstName()
  {  return first;  }

  public String getLastName()
  {  return last;  }

  public String toString()
  {  return "Hi, I'm " + getFirstName() + " " + getLastName();  }
}

  -- GG


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.