I am working on a project where I need to work with ontologies in java. I am
reading an ontology into an OWLModel. I am also reading in another ontology
into an OntModel. Following which I am making SPARQL query on the OntModel
and hence taking out data from the OntModel into my data structure. Then, I
generate SWRL rules from the values stored in the data structure. The SWRL
rules generated are correct as I successfully copy-pasted (and also inferred
from) them in the Protege's Rules tab. Next, I am adding the SWRL rules to
the OWLModel using SWRLFactory in the following manner:

//'owlModel' HAS THE ONTOLOGY IN THE OWLModel FORMAT.
factory = new SWRLFactory(owlModel);

//'body' HAS THE BODY PART OF THE GENERATED RULE IN THE FORM:
//"SuperOntologyTC_105.15(?a)^ SuperOntology:Active(?a,"no")^
SuperOntology:givesError(?a,?p)"

//'head' HAS THE HEAD PART OF THE GENERATED RULE IN THE FORM:
//" -> SuperOntologyescription(?p,"DTC_Inactive")"

imp = factory.createImp(body+head);

I am also adding all the variables used in the rules by
//VAR1 HAS VARIABLES LIKE 'a' OR 'p' ETC
variable1 = factory.createVariable(var1);

Lastly, I am saving the OWLModel ontology to the hard disk. It is here in
the last step that I am encountering a problem which I am not able to figure
out. The following stack is displayed:

Loading triples for: null
Completed triple loading after 59 ms
Postprocess: Process entities with incorrect Java type (1 entities) ... 1 ms
Postprocess: Process metaclasses (3 metaclasses) ... 0 ms
Postprocess: Process subclasses of rdf:List (1 classes) ... 0 ms
Postprocess: Instances with multiple types (1 instances) ... 0 ms
Postprocess: Add inferred superclasses ... 0 ms
Postprocess: Process orphan classes (17 classes) ... 2 ms
Postprocess: Generalized Concept Inclusion (0 axioms) ... 3 ms
Postprocess: Abstract classes... 0 ms
Postprocess: Domain and range of properties... 10 ms
Postprocess: Possibly typed entities (2 resources) ... 0 ms
Updating underlying frames model in 0 ms
Apr 10, 2010 6:18:21 AM
edu.stanford.smi.protegex.owl.jena.parser.ProtegeO WLParser
doFinalPostProcessing
INFO: Updating underlying frames model in 0 ms
Loading triples for: null
Completed triple loading after 135 ms
Postprocess: Process entities with incorrect Java type (1 entities) ... 0 ms
Postprocess: Process metaclasses (3 metaclasses) ... 0 ms
Postprocess: Process subclasses of rdf:List (1 classes) ... 0 ms
Postprocess: Instances with multiple types (10 instances) ... 2 ms
Postprocess: Add inferred superclasses ... 0 ms
Postprocess: Process orphan classes (17 classes) ... 0 ms
Postprocess: Generalized Concept Inclusion (0 axioms) ... 0 ms
Postprocess: Abstract classes... 0 ms
Postprocess: Domain and range of properties... 3 ms
Postprocess: Possibly typed entities (2 resources) ... 0 ms
Updating underlying frames model in 0 ms
Apr 10, 2010 6:18:21 AM
edu.stanford.smi.protegex.owl.jena.parser.ProtegeO WLParser
doFinalPostProcessing
INFO: Updating underlying frames model in 0 ms

//SO LOADING THE FIRST ONTOLOGY INTO OWLMODEL IS DONE.
//DATA STRUCTURE TRAVERSAL BEGINS
//SWRL RULES ARE GENERATED AND ADDED TO THE OWLMODEL USING SWRLFACTORY

//NOW STARTING TO PRINT OWLMODEL TO FILE
SEVERE: Failed to save file file:/E:/OutWithRules.owl using Protege2Jena. --
com.hp.hpl.jena.shared.BadURIException: Only well-formed absolute URIrefs
can be included in RDF/XML output: <nullRule-4> Code:
57/REQUIRED_COMPONENT_MISSING in SCHEME: A component that is required by the
scheme is missing.
at
com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.check URI(BaseXMLWriter.java:829)
at
com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.relat ivize(BaseXMLWriter.java:806)
at com.hp.hpl.jena.xmloutput.impl.Unparser.wURIrefere nce(Unparser.java:881)
at com.hp.hpl.jena.xmloutput.impl.Unparser.wURIrefere nce(Unparser.java:885)
at com.hp.hpl.jena.xmloutput.impl.Unparser.wAboutAttr (Unparser.java:876)
at
com.hp.hpl.jena.xmloutput.impl.Unparser.wIdAboutAt trOpt(Unparser.java:832)
at
com.hp.hpl.jena.xmloutput.impl.Unparser.wTypedNode OrDescriptionLong(Unparser.java:793)
at
com.hp.hpl.jena.xmloutput.impl.Unparser.wTypedNode OrDescription(Unparser.java:727)
at com.hp.hpl.jena.xmloutput.impl.Unparser.wTypedNode (Unparser.java:700)
at com.hp.hpl.jena.xmloutput.impl.Unparser.wObj(Unpar ser.java:640)
at com.hp.hpl.jena.xmloutput.impl.Unparser.wObjStar(U nparser.java:317)
at com.hp.hpl.jena.xmloutput.impl.Unparser.wRDF(Unpar ser.java:298)
at com.hp.hpl.jena.xmloutput.impl.Unparser.write(Unpa rser.java:200)
at
com.hp.hpl.jena.xmloutput.impl.Abbreviated.writeBo dy(Abbreviated.java:143)
at
com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.write XMLBody(BaseXMLWriter.java:500)
at
com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.write (BaseXMLWriter.java:472)
at com.hp.hpl.jena.xmloutput.impl.Abbreviated.write(A bbreviated.java:128)
at edu.stanford.smi.protegex.owl.jena.JenaOWLModel.sa veModel(Unknown
Source)
at edu.stanford.smi.protegex.owl.jena.JenaOWLModel.sa ve(Unknown Source)
at edu.stanford.smi.protegex.owl.jena.JenaOWLModel.sa ve(Unknown Source)
at
edu.stanford.smi.protegex.owl.jena.protege2jena.Pr otege2Jena.saveAll(Unknown
Source)
at edu.stanford.smi.protegex.owl.jena.JenaOWLModel.sa ve(Unknown Source)
at module2.main(module2.java:899)

Exception in thread "main" java.lang.NullPointerException
at edu.stanford.smi.protegex.owl.jena.JenaOWLModel.sa ve(Unknown Source)
at module2.main(module2.java:899)