CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 1999
    Posts
    2

    Code hangs - don't know why!



    I have defined an object(Tracker) with four variables and in a class have declared an array of this object:

    Tracker track[] = new Tracker[max];

    However in a for loop when I try to set the values of the variables The code hangs for no apparent reason.


    for (int i = 0; i < track.length; i++){

    track[i].agname = agNames[i];

    track[i].priority = priority[i];

    }


    Would anyone have any ideas???


    Hilary



  2. #2
    Join Date
    Mar 1999
    Posts
    8

    Re: Code hangs - don't know why!



    Hi Hilary,

    could you please send the entire code(How does your Tracker class look like?)


    Ajay

  3. #3
    Join Date
    Apr 1999
    Posts
    2

    Re: Code hangs - don't know why!



    below is the code for the Tracker. It is instantiated in an agent. I didn't supply all this code but the beginning. You

    couldn't run it without the agent platform.



    package IE.BROADCOM.ISYS.ASL.Hilary;


    //ASL imports

    import IE.BROADCOM.ISYS.ASL.agentName;



    public class Tracker{

    agentName agname = null;

    String reply = null;

    int priority = 0;

    int times[] = {6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,00}; //max number of hours to be dealt with



    public Tracker(){

    agname = null;

    reply = null;

    priority = 0;

    }


    public int findTime(Tracker[] tracker, int numAgents){

    int proposeTime = 9; //earliest one would want a meeting at?

    for (int i = 0; i < numAgents; i++){

    for (int j = 9; j < 18; j++){

    if (tracker[i].times[j] == tracker[i+1].times[j])

    proposeTime = tracker[i].times[j];

    }

    }



    return proposeTime;

    }


    }



    agent:...........

    public class PersonalAgentTwo extends BasicAgent{


    private ContentParser parser = null; //instance of class to parse messages

    private Schedule sched = null;

    //private InformationManager infoMgr = null; //instance of class to interface with Outlook

    String action = null;

    String date = null;

    String loc = null;

    String time = null;

    String list = null;

    String duration = null;

    String newContent = null;

    String request = null;


    int count = 0;

    static final int maxHrs = 18; //schedule only deals with 18 hours of the day!!

    final int maxAgs = 5; // number of agents listed in meeting request!

    int nums = 0;

    int tempTimes[] = new int[maxHrs];

    int freeTimes[] = {6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,00};

    agentName agNames[] = new agentName[maxAgs];

    int priority[] = new int[maxAgs];

    String reply[] = new String[maxAgs];

    int suggestTime = 9; //don't really want a meeting earlier than this unless absolutely

    necessary!


    //keep track of all agents requested to meeting and their replies

    private Tracker track[] = new Tracker[maxAgs];


    DataInputStream iStream = new DataInputStream(System.in);




    public PersonalAgentTwo (agentName name, String type, String kind, IaNS ia, ACA aca){

    super(name, type, kind, ia, aca);



    parser = new ContentParser();

    sched = new Schedule("Pa2"

    //infoMgr = new OutlookManager();

    System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"

    System.out.println("~~~~ Personal AGENT (2) ~~~~"

    System.out.println("~~~~ Personal Assistant by Hilary Reynolds ~~~~"

    System.out.println("~~~~ January 1999 ~~~~"

    System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"



    }



    public void startMessage(){

    try{

    System.out.println ("Enter the action for the message: \n"

    action = iStream.readLine();

    System.out.println ("Enter the date for this meeting: \n"

    date = iStream.readLine();

    System.out.println ("Enter the location for this meeting: \n"

    loc = iStream.readLine();

    // System.out.println("Enter the duration for this meeting: \n"

    // duration = iStream.readLine();

    System.out.println ("Enter the list of attendees for this meeting: \n"

    list = iStream.readLine();

    }

    catch(IOException ioe){

    System.out.println("Error inputing data: " + ioe + "\n"

    }



    newContent = ("(" + action + ",(" + date + ":" + loc + &quot)"


    java.util.Vector pp = parser.parseList(list);





    if (pp != null){

    String number = (String) pp.elementAt(0);

    nums = java.lang.Integer.parseInt(number);

    agNames = (agentName[]) pp.elementAt(1);

    priority = (int[]) pp.elementAt(2);


    for (int i = 0; i < track.length; i++){

    System.out.println("initialising tracker"

    System.out.println(agNames[i].name );

    track[i].agname = agNames[i];

    track[i].priority = priority[i];

    }


    kqmlExp bMessage = initMessage();

    bMessage.content = newContent;

    bMessage.perfType = performatives.ASK;

    System.out.println(" [ Sending message now! ] "

    broadcastMessage( agNames, bMessage);

    }

    else{

    System.out.println("[ Error while parsing attendance list:: Try Again! ]"

    //go back to the start

    }

    }

  4. #4
    Guest

    Re: Code hangs - don't know why!

    Maybe you could add one line to initialize the tracker object before you use it.

    for (int i = 0; i < track.length; i++)
    {
    track[i] = new Tracker();

    track[i].agname = agNames[i];
    track[i].priority = priority[i];
    }

    Shuli



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured