Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xampp tool 12 56
tomcat startup error 5 107
Android development question 2 55
jmss example java 2 24
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

821 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