Solved

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

Posted on 2011-03-19
2
315 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
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…
The viewer will learn how to implement Singleton Design Pattern in Java.

691 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