3

I'm quite a noob at android programming and I'm stuck on developing an array of classes.

Exampleclass only has 2 string variables declared in it. Below is how I imagined the classes would be created:

Exampleclass something = new
Exampleclass();

Exampleclass[] something_else= new
Exampleclass[5];

When trying to assign string variables to one of the array classes, it just crashes. When debugging I found that single classes had both string values & their names were appearing fine, but each array was just appearing with a single null value, no string or name.

Is there any particular way to setup a class, or create one, for arrays?

1
  • What are you trying to achieve? Commented Apr 1, 2011 at 12:29

1 Answer 1

4

You only initialized the array, not the objects inside of it, you should use:

Exampleclass[] something_else = new Exampleclass[5]; // initialize array
for (int i = 0; i < something_else.length; i++)
    something_else[i] = new something_else();    // initialize each object in the array
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.