Link to home
Start Free TrialLog in
Avatar of jc31415
jc31415

asked on

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;
}
ASKER CERTIFIED SOLUTION
Avatar of _lychee_
_lychee_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shaveri
shaveri

exactly.....