在创建Ontology类期间转换时出错

时间:2014-08-28 11:24:00

标签: java agents-jade

我创建了一个词汇表Network_Vocabulary interface

我创建了一个类CustomerAgentStatus来实现AgentAction

然后我创建了一个本体类,将本体定义为:

我收到的错误是:

 java.lang.ExceptionInitializerError

然后我按照以下类似问题的建议按照说明操作: http://jade.tilab.com/pipermail/jade-develop/2013q3/019284.html

因此我把

    **ontology =  NetworkOntology.getInstance();**

在setup()方法中,并用try / catch

包围它

堆栈跟踪后我得到以下错误,我觉得本体类中有一些错误:

我收到的错误是:

 Java.Lang.ClassCastException: jade.content.schema.Concept Schema cannot be cast to jade      .content.schema.PrimitiveSchema** 

我的Ontology类实现如下:

package CellularNetwork;
import jade.content.onto.*;

import jade.content.schema.*;

public class Network_Ontology extends Ontology implements Network_Vocabulary {
public static final String ONTOLOGY_NAME = "Network-Ontology";
private static Ontology instance = new Network_Ontology();
public static Ontology getInstance() { return instance; }
// Private constructor

private Network_Ontology() {

  super(ONTOLOGY_NAME, BasicOntology.getInstance());

  try{

            AgentActionSchema cs = new AgentActionSchema(CUSTOMERAGENTSTATUS);

            add(cs, CustomerAgentStatus.class);

            cs.add(X_CO_ORDINATE, (PrimitiveSchema) getSchema(BasicOntology.FLOAT));

            cs.add(Y_CO_ORDINATE, (PrimitiveSchema) getSchema(BasicOntology.FLOAT));

            cs.add(DIRECTION, (PrimitiveSchema) getSchema(BasicOntology.STRING));

            cs.add(SPEED, (PrimitiveSchema) getSchema(BasicOntology.FLOAT));

            cs.add(CURRENT_PROVIDER,(PrimitiveSchema) getSchema(BasicOntology.AID));        

  }

  catch (OntologyException oe) {

  oe.printStackTrace();

  }

  }

 }// Network_Ontology

1 个答案:

答案 0 :(得分:0)

如果试图用AID表示CURRENT_PROVIDER对象,则必须将此架构添加为ConceptSchema对象,而不是PrimitiveSchema对象。只需更改此行:

cs.add(CURRENT_PROVIDER,(PrimitiveSchema) getSchema(BasicOntology.AID)); 

对此:

cs.add(CURRENT_PROVIDER,(ConceptSchema) getSchema(BasicOntology.AID));