954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Instantiating objects to be referenced in nested classes

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.

wiredin
Newbie Poster
1 post since Sep 2011
Reputation Points: 10
Solved Threads: 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?

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: