Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

760 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

16 Experts available now in Live!

Get 1:1 Help Now