Elements of a Java Object Array are created but without correct names

Posted by Greenhouse Gases on Stack Overflow See other posts from Stack Overflow or by Greenhouse Gases
Published on 2010-04-15T13:21:44Z Indexed on 2010/04/15 13:23 UTC
Read the original article Hit count: 177

Filed under:
|

Hi all

Im having rather an annoying problem. I have a class called Person and a class called Event which serve to create objects to be used for competitors that compete in a certain event. When I add a competitor thats fine and the GUI list updates accordingly, however when I add an event the element in the array does not take on the value of the instance variable name in the class Event and so the GUI does not show the event name, though it is being added in the array correctly. How can I make it so that the event object in each element of the listOfEvents array (which is an array of event objects) has the name of the event. I should add this is for university though this isnt the part for which we will be assessed, it is somethign i have come across and due to not being able to see the code for the GUI, I've hit the proverbial brick wall.

I wont include the whole load of code Ive been writing but hopefully my description and snippets below will suffice. Any advice I would appreciate greatly. No doubt I have overlooked something simple! Many thanks.

listOfEvents is declared as:

Event[] listOfEvents = new Event[20];

A snippet from the Event class:

public class Event {

String name;

Person[] participants = new Person[10]; // array of competitors for the event


public Event(String name) {

    this.name = name;

}

}

and its use in the addEvent method (p is a global variable):

  public void addEvent(String eventName) {



  listOfEvents[p] = new Event(eventName);
  p++;

}

© Stack Overflow or respective owner

Related posts about university

Related posts about java