Envoi de message entre 2 agents avec JADE

Résolu/Fermé
RJ1 Messages postés 20 Date d'inscription lundi 8 mai 2017 Statut Membre Dernière intervention 16 mai 2017 - 8 mai 2017 à 13:57
RJ1 Messages postés 20 Date d'inscription lundi 8 mai 2017 Statut Membre Dernière intervention 16 mai 2017 - 8 mai 2017 à 23:11
Bonjour,
j'ai 2 agents coordinateur qui envoi un msg au deuxième agent véhicule puis l'agent véhicule doit envoyer un msg à l'agent Coordinateur !
mon probleme que l'agent véhicule ne peut pas envoyer le msg j'ai utilisé la méthode getSender()



mai 08, 2017 12:55:51 PM jade.core.Runtime beginContainer
INFOS: ----------------------------------
This is JADE 4.4.0 - revision 6778 of 21-12-2015 12:24:43
downloaded in Open Source, under LGPL restrictions,
at http://jade.tilab.com/
----------------------------------------
mai 08, 2017 12:55:51 PM jade.imtp.leap.LEAPIMTPManager initialize
INFOS: Listening for intra-platform commands on address:
- jicp://192.168.1.4:1099

mai 08, 2017 12:55:52 PM jade.core.BaseService init
INFOS: Service jade.core.management.AgentManagement initialized
mai 08, 2017 12:55:52 PM jade.core.BaseService init
INFOS: Service jade.core.messaging.Messaging initialized
mai 08, 2017 12:55:52 PM jade.core.BaseService init
INFOS: Service jade.core.resource.ResourceManagement initialized
mai 08, 2017 12:55:52 PM jade.core.BaseService init
INFOS: Service jade.core.mobility.AgentMobility initialized
mai 08, 2017 12:55:52 PM jade.core.BaseService init
INFOS: Service jade.core.event.Notification initialized
mai 08, 2017 12:55:52 PM jade.mtp.http.HTTPServer <init>
INFOS: HTTP-MTP Using XML parser com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser
mai 08, 2017 12:55:52 PM jade.core.messaging.MessagingService boot
INFOS: MTP addresses:
http://RIM-PC:7778/acc
mai 08, 2017 12:55:52 PM jade.core.AgentContainerImpl joinPlatform
INFOS: --------------------------------------
Agent container Main-Container@192.168.1.4 is ready.
--------------------------------------------
démarage de l'agent2222222
démarage de l'agent
      • Uncaught Exception for agent Véhicule ***

java.lang.NullPointerException
at rim.Véhicule$1.action(Véhicule.java:41)
at jade.core.behaviours.Behaviour.actionWrapper(Behaviour.java:344)
at jade.core.Agent$ActiveLifeCycle.execute(Agent.java:1552)
at jade.core.Agent.run(Agent.java:1491)
at java.lang.Thread.run(Unknown Source)
ERROR: Agent Véhicule died without being properly terminated !!!
State was 2
A voir également:

2 réponses

KX Messages postés 16733 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 31 janvier 2024 3 015
8 mai 2017 à 15:18
Bonjour,

java.lang.NullPointerException
at rim.Véhicule$1.action(Véhicule.java:41)
Qu'est ce que tu as comme code dans ta classe Véhicule ?
Merci de préciser où est la ligne 41...
0
RJ1 Messages postés 20 Date d'inscription lundi 8 mai 2017 Statut Membre Dernière intervention 16 mai 2017
Modifié le 8 mai 2017 à 22:50
package rim;


import jade.core.ProfileImpl;
import jade.core.Runtime;
import jade.util.ExtendedProperties;
import jade.util.leap.Properties;
import jade.wrapper.AgentContainer;
import jade.wrapper.AgentController;
import jade.wrapper.ControllerException;

public class MainContainer {

 
 public static void main(String[] args) {
  try {
   
   
   Runtime rt = Runtime.instance();
   Properties p=new ExtendedProperties();
   p.setProperty("gui", "true");
   ProfileImpl pc=new ProfileImpl(p);
   AgentContainer container=rt.createMainContainer(pc);
   

   
   
   container.start();
   
   
 
AgentController agentController1= container.createNewAgent("coordinateur", "rim.Coordinateur", new Object[] {""});
   
            agentController1.start(); 
   
AgentController agentController= container.createNewAgent("véhicule", "rim.Véhicule", new Object[] {""});
   
            agentController.start(); 
            

            


  }
  catch (ControllerException e) {
   e.printStackTrace();
  }
 } 

 

}

package rim;

import jade.core.AID;
import jade.core.Agent;
import jade.core.behaviours.CyclicBehaviour;
import jade.lang.acl.ACLMessage;


public class Coordinateur extends Agent{


 @SuppressWarnings("serial")
 @Override
 protected void setup() {
  
  System.out.println("démarage de l'agent");

   addBehaviour(new  CyclicBehaviour() {
    
  @Override
 
public void action() {

     ACLMessage message = new ACLMessage(ACLMessage.INFORM);
     message.addReceiver(new AID("Véhicule",AID.ISLOCALNAME));
     message.setContent("alooooooo");

     send(message);
    }

    
    }
   

     
     );
   
  
  
  }
  

}

package rim;



import jade.core.Agent;
import jade.core.behaviours.OneShotBehaviour;
import jade.lang.acl.ACLMessage;


@SuppressWarnings("serial")
public class Véhicule extends Agent {
 
 
 
 protected void setup() {
  
  System.out.println("démarage de l'agent2222222");

   addBehaviour(new OneShotBehaviour() {
   

    public void action() {
 
     ACLMessage message= receive();
     if (message!= null){
       System.out.println("Message received" + message.getContent());
        
     }
     else  { 
      block();
      }
     
     
     

ACLMessage message1 = new ACLMessage(ACLMessage.INFORM);
message1.addReceiver(message.getSender());
message1.setContent("la reponse");  
send(message1); 
     
     
    }
    
   
   });
  
  }
  


 
 

}
0
RJ1 Messages postés 20 Date d'inscription lundi 8 mai 2017 Statut Membre Dernière intervention 16 mai 2017
8 mai 2017 à 22:43
l'erreur qui s'affiche

mai 08, 2017 9:39:47 PM jade.core.Runtime beginContainer
INFOS: ----------------------------------
This is JADE 4.4.0 - revision 6778 of 21-12-2015 12:24:43
downloaded in Open Source, under LGPL restrictions,
at http://jade.tilab.com/
----------------------------------------
mai 08, 2017 9:39:47 PM jade.imtp.leap.LEAPIMTPManager initialize
INFOS: Listening for intra-platform commands on address:
- jicp://192.168.1.5:1099

mai 08, 2017 9:39:47 PM jade.core.BaseService init
INFOS: Service jade.core.management.AgentManagement initialized
mai 08, 2017 9:39:47 PM jade.core.BaseService init
INFOS: Service jade.core.messaging.Messaging initialized
mai 08, 2017 9:39:47 PM jade.core.BaseService init
INFOS: Service jade.core.resource.ResourceManagement initialized
mai 08, 2017 9:39:47 PM jade.core.BaseService init
INFOS: Service jade.core.mobility.AgentMobility initialized
mai 08, 2017 9:39:47 PM jade.core.BaseService init
INFOS: Service jade.core.event.Notification initialized
mai 08, 2017 9:39:47 PM jade.mtp.http.HTTPServer <init>
INFOS: HTTP-MTP Using XML parser com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser
mai 08, 2017 9:39:47 PM jade.core.messaging.MessagingService boot
INFOS: MTP addresses:
http://RIM-PC:7778/acc
mai 08, 2017 9:39:47 PM jade.core.AgentContainerImpl joinPlatform
INFOS: --------------------------------------
Agent container Main-Container@192.168.1.5 is ready.
--------------------------------------------
démarage de l'agent2222222
ERROR: Agent véhicule died without being properly terminated !!!
State was 2
démarage de l'agent
      • Uncaught Exception for agent véhicule ***

java.lang.NullPointerException
at rim.Véhicule$1.action(Véhicule.java:37)
at jade.core.behaviours.Behaviour.actionWrapper(Behaviour.java:344)
at jade.core.Agent$ActiveLifeCycle.execute(Agent.java:1552)
at jade.core.Agent.run(Agent.java:1491)
at java.lang.Thread.run(Unknown Source)
0
KX Messages postés 16733 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 31 janvier 2024 3 015
8 mai 2017 à 23:02
Si la ligne 37 qui est dans ton message d'exception (qui était la ligne 41 avant) est bien celle qui apparaît ligne 37 dans le code ci-dessus alors le problème vient de
message
qui vaut null, ce qui fait planter
message.getSender()
ligne 37.

Tu as déjà un test
if (message!= null){
mais il ne s'applique pas sur ta ligne 37 donc il faudrait corriger ça pour gérer tous les cas. exemple :

protected void setup() {
    System.out.println("démarage de l'agent2222222");

    addBehaviour(new OneShotBehaviour() {
        @Override
        public void action() {
            ACLMessage message = receive();
            if (message != null) {
                System.out.println("Message received" + message.getContent());
                ACLMessage message1 = new ACLMessage(ACLMessage.INFORM);
                message1.addReceiver(message.getSender());
                message1.setContent("la reponse");
                send(message1);
            } else {
                block();
            }
        }
    });
}
0
RJ1 Messages postés 20 Date d'inscription lundi 8 mai 2017 Statut Membre Dernière intervention 16 mai 2017 > KX Messages postés 16733 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 31 janvier 2024
8 mai 2017 à 23:11
Merci
J'ai changé le code le msg de l'agent coordinateur vers l'agent véhicule ça marche bien mais non pour l'inverse c'est à dire le msg de l'agent véhicule vers l'agent coordinateur ne s'envoi pas
0