0

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.

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by NormR1
0

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?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.