I need to make 45 objects of a nested class within my main class. I have tried instantiating the objects inside the main class' data fields and then inside of its default constructor. After being instantiated, i need to add 15 of the objects to 15 more arrays (each object in three different arrays), and reference them in a nested classes and the main method. As a result, instantiating and adding them to the arrays cannot be performed in the main method as they would not be able to be referenced in nested classes if they are made at runtime. I create the 45 objects of the nested class called 'buttonouter' using an array. The code for instantiating them is as follows.

public static buttonouter outers[];
outers = new button outer[45];
for (int x = 0; x < 45; x++)
{
outers[x] = new button outer();
}

If there is no problem with this code, then I do not know what the problem is. When I try to reference the objects using an array and index (arrayName[index]) in another nested class or even the main method i get null pointer exception errors. I can post the code if necessary. Thanks very much.

When I try to reference the objects using an array and index (arrayName[index]) in another nested class or even the main method i get null pointer exception errors

Can you post a small simple program that executes and demonstrates the problem?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.