Solved

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

Posted on 2011-03-19
2
309 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Where to store the queries for modification of table 4 62
stackato and cloud 4 85
print map entry 34 69
tomcat startup error 5 65
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

810 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