Creating array of a class

I am trying to add an array of a newly defined class to a working program. It complies ok, but when I run it I get "java.lang.NullPointerException" at line new. The statement at line old runs
just fine. How can the oldArray work and the newArray not?

Exerpted code:
                       
public class test extends JPanel implements ActionListener{
   public test(){
      ...
      function1();
      ...      
   public void function1(){
      oldArray[0].first=0;   // line old
      newArray[0].first=0;   // line new
      ...
   oldClass[] oldArray=new oldClass[5];
   newClass[] newArray=new newClass[5];
   ...
class oldClass{
   int first;
}
class newClass{
   int first;
}
jc31415Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_lychee_Commented:
do you ?accidentally? put an oldClass object into oldArray[0]?
cos if u don't, both statements shouldn't work... this is cos the statement

A[] a = new A[5];
only says that a is an array of size 5 of A, but A[0], A[1], ... A[4] are all null at the start.. you need to do something like A[0] = new A(); to "put" the object into the array...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shaveriCommented:
exactly.....
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.