I want to add values into it but when i try it tells me there is a NullPointerException. I understand what this means so my question is simply, therefore, how do you actually add values into the array. My code is similar to the following that is in a loop.:
You don't have an array. You have a variable of array type. You haven't allocated an array object for it to point to, so it's null. Therefore trying to store an object into it gives a NullPointerException.
I think you can better use a List (ArrayList). This is a default interface from the java.util package which handles resizing for you.
There is one problem with List in Java 1.4 and earlier: you can't put primitives in. To put ints in a List you must create an Integer object and put that in the List. Likewise, when you retrieve it from the List, you must first cast the Object to Integer, than retrieve the value through intValue().
Java 1.5 can do much of this work for you. Firstly, you can create a List that can only except Integer objects. Secondly, autoboxing does the conversion between Integer and int for you.