Solved

Items not being added through GUI but can be added to ArrayList from input file

Posted on 2011-03-19
2
307 Views
Last Modified: 2012-05-11
I had to redesign the classes (it was dictated to me that they be as they are - Person,Friend,Address) the rest is my own AddressBook (main class), AddressBookGUI, BookActions, and Contact (should be ContactList) - for processing objects into an ArrayList.
 AddressBook.java  AddressBookGUI.java BookActions.java Contact.java Person.java Friend.java

these are what I am working with.

The problem I am now having is retrieving text from the textfields into the Friend Constructor in the addNewContact() method in the BookAction class.
 
public void addNewContact() {
        System.out.println(c.contactsSize());
        String lName = abg.lastName.getText();
        String fName = abg.firstName.getText();
        String mName = abg.middleName.getText();
        String hPhone = abg.homePhone.getText();
        String cPhone = abg.cellPhone.getText();
        String streetName = abg.streetName.getText();
        String cityName = abg.cityName.getText();
        String stateName = abg.stateName.getText();
        String zipCode = abg.zipCode.getText();

        f = new Friend(lName, fName, mName, hPhone, cPhone);
        a = new Address(streetName, cityName, stateName, zipCode);
        c.addContacts(f);
        clearAll();
        System.out.println(c.getContacts());
    }

Open in new window


I get a null pointer exception from trying to retrieve the ArrayList size or the same exception when trying to add the friend object.

I'm not sure what is wrong becaue the arrayList returns "11" as a size and also displays all the contact objects read from the input file.

Address.java
0
Comment
Question by:g_currier
2 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 35173438
c is null, you need to initialise it before adding things to it
0
 

Author Closing Comment

by:g_currier
ID: 35176061
that worked, thanks
(I've got a few more issues (next posting)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now