NullPointerException on retrieving data


Im using the AppFoundation add-on to add persistence to the address book demo. I’ve followed the instructions given on:

However im getting a NullPointerException when im trying to fetch the data from my database. I have also looked at the source code for the example and its the same as my code. The NullPointerException occurs at:

List<City> cities = FacadeFactory.getFacade().list(City.class);

In my case im using an entity class City instead of Person.

I have my db set up with the correct config as described on the AppFoundation documentation. The table exists on the database with sample data.

Any ideas why im getting the NullPointerException?

Another question i have is, how do i specify the actual table name i want to retrieve data from? Can this be different from the entity name? For example, In the address book demo Person object are saved to the PERSON table.



Can anyone help with this?

I have my persistence.xml file in src/META-INF

The username and password are correct.

I am trying to read the data in the database table into the GUI table. Ive already registered the facade.

I’ve tried to get a count of rows in my table:

Long count = FacadeFactory.getFacade().count(City.class);

still getting a NullPointerException

I’ve checked if my facade is registered:

IFacade facade = FacadeFactory.getFacade();

which returns no errors. So this indicates that there is a problem with either the db connection or the connection to the table. The DB and table exist. I have named the table the same as the entity class CITY. My persistence.xml file specifies the name of the db which is “examples” and also has the entity class. The username and password are ok as ive checked this by creating a class which connected to the db and retrieves all the values from the table CITY. So the details are correct. I think this points to my entity class? Or is it a config issue.

I have also tried to store data. Changed the persistence.xml to create tables and added the following to an init method which is called in the contextListner class:


Any pointers as to what might be the issue or how i can troubleshoot?

any help is much appreciated

Spring app
. I don’t get that AppFoundation library. Only think I could use from that is view module.

thanks Petri,

I really like the look of the AppFoundation add-on. It seems very easy to use but i am dissapointed that i cannot get it to work correctly.

Ive raised an issue on the project page to see if i can get any more pointers.

What i am looking for is an easy way to read, write and update tables in my database.

Could you please provide the first couple of lines of the NullPointerException.

Thanks for getting back to me Kim, details below:

at com.demo.addressbook.ui.DemoApplication.(
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

Line 75 in

List<City> cities = FacadeFactory.getFacade().list(City.class);

Lines 92-96 in

public static CityContainer createAndPopulatedContainer() {
    	CityContainer c = null;
        try {
            c = new CityContainer();

ok, looks like i omitted the listner entry in web.xml:


I am one step closer now. Getting the following error now:

Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column ‘ID’ in ‘field list’
Error Code: 1054

I dont have an ID column in my table. Ive set the primary key to another id column called cityID.

Im having a look at:

Thanks to all that helped