Hallo Allerseit,
ich bin nochmal mit meine Probleme ...
Ich habe ne array definiert als public static, aber irgendwie habe ich falsch gemacht, da das Program hoert auf in
folgende line
<code>
agent = a;
</code>
- In line 4 und 5 definiere ich die Array fuer role und agent (mein Problem lag vielleicht hier?)
- dann in function onMessage, bekomme ich dann Daten von anderen Applikation
- agentNumber (int)
- agent0= "A",agent1="B", agent2="C"
- role0="1", role1="2", role2="3"
- diese Line funktioniert noch
<code>
System.out.println( a +" is a "+ r)
</code>
- danach schicke ich dann die value von a, r und i zu inputAgent(a, r, i)
- Diese Line funktioniert noch
<code>
System.out.println( a+" "+r+" "+i+" "+ s);
</code>
- Aber als ich die value von a zu agent eingebe, dann hoert das Program auf
Was habe ich falsch gemacht?
Habe zwar ein paar Beitraege in Forum gelesen, aber ich weiss nicht was ist der Fehler, habe eigentlich vorher
direkt in onMessage die array benutzt (zwischen line 25-33), aber ging nicht, dann habe ich mit function inputAgent probiert, funktioniert auch nicht .....
vielen Dank erstmal fuer Eure Hilfe ...
---
<code>
package guiClient;
public class GuiClient implements MessageListener
{
public static String[] agent ;
public static String[] role ;
private int agentNumber;
protected static ClientCommunication comm;
public GuiClient()
{
// create the AgentSystem connection
// set the client identifier for the RFID reader
}
public void onMessage(ClientCommunication arg0, long arg1)
{
// retrieve pending message
IReceivedMessage message = (IReceivedMessage)arg0.getMessage(arg1);
if (message.getPerformative().equals(PERF_REPLY+"-agents"))
{
agentNumber=(message.getFromContent("count").hashCode());
if (agentNumber != 0 )
{
System.out.println("no.of agents: "+ agentNumber);
for (int i=0; i<agentNumber; ++i)
{ String a= (String) message.getFromContent("agent"+i);
String r = (String) message.getFromContent("role"+i);
System.out.println( a +" is a "+ r);
inputAgent(a,r,i);
}
}
}
// received a location message
// received a price message
// received a budget message
// receiveda schedule message
}
private void inputAgent(String a, String r, int i)
{
int s = agentNumber;
System.out.println( a+" "+r+" "+i+" "+ s);
agent = a;
System.out.println( "input Agent" + agent);
return;
}
public void requestagents()
{ IMessageToSend msg = MFactory.instance().creStatement(
AgentElFactory.creAgentIdentifier("directoryAgent"),
SUBJ_GUI_CLIENT, PERF_REQUEST+"-agents",null);
comm.sendMessage((Message)msg);
}
public void requestlocation()
{
for (int i=0; i<agentNumber; ++i)
{
System.out.println( "request loc.for" + agent);
IMessageToSend msg = MFactory.instance().creStatement(
AgentElFactory.creAgentIdentifier(agent),
SUBJ_GUI_CLIENT, PERF_REQUEST+"-location",null);
comm.sendMessage((Message)msg);
}
}
public void requestprices()
{ //same procedure as request location}
public void requestschedule()
{ //same procedure as request location}
public static void main(String[] args) throws IOException
{
}
</code>
ich bin nochmal mit meine Probleme ...
Ich habe ne array definiert als public static, aber irgendwie habe ich falsch gemacht, da das Program hoert auf in
folgende line
<code>
agent = a;
</code>
- In line 4 und 5 definiere ich die Array fuer role und agent (mein Problem lag vielleicht hier?)
- dann in function onMessage, bekomme ich dann Daten von anderen Applikation
- agentNumber (int)
- agent0= "A",agent1="B", agent2="C"
- role0="1", role1="2", role2="3"
- diese Line funktioniert noch
<code>
System.out.println( a +" is a "+ r)
</code>
- danach schicke ich dann die value von a, r und i zu inputAgent(a, r, i)
- Diese Line funktioniert noch
<code>
System.out.println( a+" "+r+" "+i+" "+ s);
</code>
- Aber als ich die value von a zu agent eingebe, dann hoert das Program auf
Was habe ich falsch gemacht?
Habe zwar ein paar Beitraege in Forum gelesen, aber ich weiss nicht was ist der Fehler, habe eigentlich vorher
direkt in onMessage die array benutzt (zwischen line 25-33), aber ging nicht, dann habe ich mit function inputAgent probiert, funktioniert auch nicht .....
vielen Dank erstmal fuer Eure Hilfe ...
---
<code>
package guiClient;
public class GuiClient implements MessageListener
{
public static String[] agent ;
public static String[] role ;
private int agentNumber;
protected static ClientCommunication comm;
public GuiClient()
{
// create the AgentSystem connection
// set the client identifier for the RFID reader
}
public void onMessage(ClientCommunication arg0, long arg1)
{
// retrieve pending message
IReceivedMessage message = (IReceivedMessage)arg0.getMessage(arg1);
if (message.getPerformative().equals(PERF_REPLY+"-agents"))
{
agentNumber=(message.getFromContent("count").hashCode());
if (agentNumber != 0 )
{
System.out.println("no.of agents: "+ agentNumber);
for (int i=0; i<agentNumber; ++i)
{ String a= (String) message.getFromContent("agent"+i);
String r = (String) message.getFromContent("role"+i);
System.out.println( a +" is a "+ r);
inputAgent(a,r,i);
}
}
}
// received a location message
// received a price message
// received a budget message
// receiveda schedule message
}
private void inputAgent(String a, String r, int i)
{
int s = agentNumber;
System.out.println( a+" "+r+" "+i+" "+ s);
agent = a;
System.out.println( "input Agent" + agent);
return;
}
public void requestagents()
{ IMessageToSend msg = MFactory.instance().creStatement(
AgentElFactory.creAgentIdentifier("directoryAgent"),
SUBJ_GUI_CLIENT, PERF_REQUEST+"-agents",null);
comm.sendMessage((Message)msg);
}
public void requestlocation()
{
for (int i=0; i<agentNumber; ++i)
{
System.out.println( "request loc.for" + agent);
IMessageToSend msg = MFactory.instance().creStatement(
AgentElFactory.creAgentIdentifier(agent),
SUBJ_GUI_CLIENT, PERF_REQUEST+"-location",null);
comm.sendMessage((Message)msg);
}
}
public void requestprices()
{ //same procedure as request location}
public void requestschedule()
{ //same procedure as request location}
public static void main(String[] args) throws IOException
{
}
</code>