| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
|
Greg,
I copied your code to a new project in NetBeans and it
worked fine.
You confirmed the correctness of my syntax to extract a data
field from an element in the ArrayList:
System.out.println
( personArrayList.get(0).getFirstName() );
However, your code differs from mine in that I have a
separate class with methods to load and print the ArrayList.
My project is made up of three classes: DataInputDem (GUI
display) Method insertNewPerson in class PersonQueries
loads the ArrayList from the object newPerson:
public
static int printArrayList (Person newPerson, ArrayList personArrayList)
Method printArrayList
in class PersonQueries prints the ArrayList:
public
static void printArrayList(ArrayList personArrayList)
The statement “System.out.println ( personArrayList.get(0).getFirstName() );” works fine in the class DataInputDemo
where the ArrayList is instantiated but not in the printArrayList method.
I don’t understand what is happing. It appears that the ArrayList is being
loaded correctly from the newPerson
object in method insertNewPerson
and that the ArrayList is being passed correctly
to the method
printArrayList, but none of the methods are found.
Below is a copy of the error message I am getting:
Created dir:
/Users/broghamerjt/MyJavaProjects/DataInputDemo/build/classes
Compiling 3 source files to
/Users/broghamerjt/MyJavaProjects/DataInputDemo/build/classes
/Users/broghamerjt/MyJavaProjects/DataInputDemo/src/datainputdemo/PersonQueries.java:85:
cannot find symbol
symbol : method
getFirstName()
location: class java.lang.Object
+ personArrayList.get(0).getFirstName());
Note:
/Users/broghamerjt/MyJavaProjects/DataInputDemo/src/datainputdemo/PersonQueries.java
uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
BUILD FAILED (total time: 1 second)
Below is the source code for the PersonQueries class
with error statement marked in read:
/*
* PersonQueries.java
*
* Created on November 5, 2007, 11:29 PM
*
* This class accesses data structures
* to store records of type person
* in ArrayList
* and
* in MySQL Database (not yet
implemented)
*
* Author: Joseph T. Broghamer
*/
package
datainputdemo;
import
java.util.ArrayList;
import
javax.swing.JFrame;
import
javax.swing.JOptionPane;
public
class PersonQueries
{
// No-arguments Constructor
public PersonQueries()
{
System.out.println ("From class constructor in
PersonQueries");
} // end no-arguments
constructor PersonQueries
public static int
insertNewPerson(Person newPerson, ArrayList personArrayList)
{
int insertresult = 0; //
used to determine if adding object (record) to ArrayList worked
// not currently implemented
System.out.println ("Printing out contents of parameter newPerson
");
System.out.println ("to ensure object data fields are correctly
populated \n");
System.out.println ("
" + newPerson.getFirstName());
System.out.println ("
" + newPerson.getLastName());
System.out.println ("
" + newPerson.getMiddleInitial());
System.out.println ("
" + newPerson.getTelephoneNumber());
System.out.println ("
" + newPerson.getApartmentSuite());
System.out.println ("
" + newPerson.getCityName());
System.out.println ("
" + newPerson.getStateName());
System.out.println ("
" + newPerson.getzipCodeName());
System.out.println ();
System.out.println
("From method insertNewPerson, "
+ "adding newPerson to personArrayList \n");
personArrayList.add(newPerson);
System.out.println ("
ArrayList index = " + personArrayList.indexOf(newPerson));
System.out.println ();
System.out.println
(personArrayList.get(0));
System.out.println ();
// Print contents of ArrayList to
scrollTextArea of GUI
// Not currently implemented
return insertresult;
} // end method
insertNewPerson
public static void
printArrayList(ArrayList personArrayList)
{
System.out.println (" From method printArraylist");
System.out.println ("Value for personArrayList.get(0) = " +
personArrayList.get(0));
System.out.println ("From class
DataInputDemo, personArrayList.get(0).getFirstName()) = "
+ personArrayList.get(0).getFirstName());
} // end method
printArraylist
} // end
class PersonQueries
On Nov 9, 2007, at 12:42 AM, Greg Guerin wrote: Joseph Broghamer wrote:Using the NetBeans debugger I was able to confirm that the data does existin ArrayList element zero (0). However, when I try to extract a dataelement from the class with a the following statement:System.out.println (personArrayList.get(0).getFirstName());I get the 'cannot find symbol' error during compile. |
_______________________________________________ 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
| References: | |
| >Re: Extracting data elements from a user-defined class stored in an ArrayList (From: Greg Guerin <email@hidden>) |
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
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.