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.NullPointerExce ption" 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;
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
exactly.....