Discussion:
[jade-develop] Error in casting during creation of the Ontology class
shreeparna sarkar
2014-08-27 11:35:04 UTC
Permalink
- I have created a vocabulary as Network_Vocabulary interface
- I have created a class CustomerAgentStatus implements the AgentAction
- I have then created an ontology class defining the ontology as:

I was getting an error as :

* java.lang.ExceptionInitializerError*

I then followed your instructions as u had suggested in a similar problem
as follows:
http://jade.tilab.com/pipermail/jade-develop/2013q3/019284.html

Accordingly i put the
ontology = NetworkOntology.getInstance();
inside the setup() method and surrounded it with try/catch

After the stack Trace i got the following errors, I feel there is some
error in the ontology class:

I'm getting an error as:
*Java.Lang.ClassCastException: jade.content.schema.Concept Schema cannot be
cast to jade .content.schema.PrimitiveSchema *

*My Ontology class implementation is as follows:*

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


Please help i'm really stuck. As i am not at all even able to track where
the error is, i m faltering.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jade.tilab.com/pipermail/jade-develop/attachments/20140827/e636a30a/attachment.html>
shreeparna sarkar
2014-08-27 19:07:43 UTC
Permalink
Sir, its very urgent . Please help. what is this ClassCast error.I could
not find any solution.




- I have created a vocabulary as Network_Vocabulary interface
- I have created a class CustomerAgentStatus implements the AgentAction
- I have then created an ontology class defining the ontology as:

I was getting an error as :

* java.lang.ExceptionInitializerError*

I then followed your instructions as u had suggested in a similar problem
as follows:
http://jade.tilab.com/pipermail/jade-develop/2013q3/019284.html

Accordingly i put the
ontology = NetworkOntology.getInstance();
inside the setup() method and surrounded it with try/catch

After the stack Trace i got the following errors, I feel there is some
error in the ontology class:

I'm getting an error as:
*Java.Lang.ClassCastException: jade.content.schema.Concept Schema cannot be
cast to jade .content.schema.PrimitiveSchema *

*My Ontology class implementation is as follows:*

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


Please help i'm really stuck. As i am not at all even able to track where
the error is,where i m faltering.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jade.tilab.com/pipermail/jade-develop/attachments/20140828/f08134dd/attachment.html>
Caire Giovanni
2014-08-29 07:18:12 UTC
Permalink
Hi,

An AID is a structured element --> Its schema is a ConceptSchema and not a PrimitiveSchema -->
The following line

cs.add(CURRENT_PROVIDER,(PrimitiveSchema) getSchema(BasicOntology.AID));
must be modified as

cs.add(CURRENT_PROVIDER,(ConceptSchema) getSchema(BasicOntology.AID));
NOTE however that since some years the JADE library includes the BeanOntology class that HARDLY simplify the definition of an ontology since you don’t have to deal with schemas anymore: you just define the ontological bean classes and you list them in your ontology class (all schemas are automatically built by the BeanOntology class).

Bye,

Giovanni

Da: jade-develop [mailto:jade-develop-bounces at avalon.tilab.com] Per conto di shreeparna sarkar
Inviato: mercoledì 27 agosto 2014 13:35
A: jade-develop at avalon.tilab.com
Oggetto: [jade-develop] Error in casting during creation of the Ontology class


* I have created a vocabulary as Network_Vocabulary interface
* I have created a class CustomerAgentStatus implements the AgentAction
* I have then created an ontology class defining the ontology as:
I was getting an error as :
java.lang.ExceptionInitializerError

I then followed your instructions as u had suggested in a similar problem as follows:
http://jade.tilab.com/pipermail/jade-develop/2013q3/019284.html

Accordingly i put the
ontology = NetworkOntology.getInstance();
inside the setup() method and surrounded it with try/catch

After the stack Trace i got the following errors, I feel there is some error in the ontology class:

I'm getting an error as:
Java.Lang.ClassCastException: jade.content.schema.Concept Schema cannot be cast to jade .content.schema.PrimitiveSchema

My Ontology class implementation is as follows:

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



Please help i'm really stuck. As i am not at all even able to track where the error is, i m faltering.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jade.tilab.com/pipermail/jade-develop/attachments/20140829/94c9b18d/attachment.html>
Loading...