Click here to Skip to main content
15,919,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Basically
Java
package CurrentGame;

//Class for holding current characters
public class Party {
        //This works :)
	public static void partygen()
	{ // declares an array of integers
              Person.Info Peep = new Person.Info();
              Peep.name="one";
              System.out.println(Peep.name);
              
              //This doesn't work :(                
              Person.Info[] PeepArr = new Person.Info[2];
              PeepArr[1].name ="one";
              System.out.println(PeepArr[1].name);
	}
}


I need to use this as an array so i can generate a party of characters for my game.
Posted
Updated 30-Apr-12 5:31am
v2
Comments
Fredrik Bornander 30-Apr-12 11:34am    
Fixed up question with pre-tags.

1 solution

You need to new up PeepArr[1] before using it, change it to this;
Java
Person.Info[] PeepArr = new Person.Info[2];
PeepArr[1].name = new Person.Info();
PeepArr[1].name ="one";
System.out.println(PeepArr[1].name);


Hope this helps,
Fredrik
 
Share this answer
 
Comments
A-s-h-l-e-y 30-Apr-12 13:42pm    
Thank you i didn't realize i had to new each item as well as on the array.
Sergey Alexandrovich Kryukov 30-Apr-12 18:26pm    
My 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900