Peter F
Peter F

Reputation: 435

Object in Object Array doesn't want to store my data

fairly new to this language. Long time lurker, first time question asker.

In my program, I load a bunch of strings from a text file and then pass all of that information inside of a String array to a program that takes the data point by point (it comes in a reliable pattern) and assigns it to variables inside a class.

I use this loop to create the objects.

Gladiator[] gladiator = new Gladiator[(match.contestants)];
for ( int a = 0; a < match.contestants; a++) {
    gladiator[a] = new Gladiator();
    gladiator[a].populategladiators(parsedInfo,a);
}

Gladiator class full of public final variables which are defined in the method populategladiators. The syntax is as follows:

this.name = parsedInfo[0+mod][0];
this.culture = parsedInfo[1+mod][0];
this.background = parsedInfo[2+mod][0];

etc.

At the moment, I only load two gladiators and it seems like maybe both are being set at once with both pass throughs? Anyone have any thoughts on this?

Also, in another method in class Gladiator, should I be able to call this.name and be okay to get data about the object I specified when calling the method?

Edit: Trying to make the code look right. Giving up since there isn't much.

2nd Edit: Example of variable declaration in gladiator class:

public static String name;
public static String culture;
public static String background;

Upvotes: 1

Views: 155

Answers (1)

Peter F
Peter F

Reputation: 435

I had my variables set as static, thus it wasn't allowing me to set individual variables for the objects. I just didn't understand what the static keyword meant.

Upvotes: 1

Related Questions