Fopa Léon Constantin
Fopa Léon Constantin

Reputation: 12383

How to proprely instantiate DatatyProperties on Jena?

I wrote the following Jena code. But It is an error and I didn't know how to address this.

Here is the code

Resource   subject   = null;
Property   property  = null;
Statement  statement = null;

...

OntModel domainModel = ModelFactory.createOntologyModel(ProfileRegistry.OWL_DL_LANG);
domainModel.read((new FileInputStream(bootstrapInOwl)), null);

subject = domainModel.getIndividual(bootbase + "Frame" + frameNum);                     
property = domainModel.getOntProperty(bootbase + "hasDuration");                
statement = domainModel.createLiteralStatement(subject, property, 12000);
domainModel.add(statement);

Here is the error message

Exception in thread "main" java.lang.NullPointerException
    at com.hp.hpl.jena.rdf.model.impl.StatementImpl.<init>(StatementImpl.java:29)
    at com.hp.hpl.jena.rdf.model.impl.ModelCom.createStatement(ModelCom.java:1116)
    at com.hp.hpl.jena.rdf.model.impl.ModelCom.createLiteralStatement(ModelCom.java:626)
    at soctrace.Intology.manageOntologies2(Intology.java:217)
    at soctrace.Intology.main(Intology.java:56)

The property hasDuration domain's is Frame Class while his range is int.

Thanks for any reply !

Upvotes: 0

Views: 132

Answers (1)

Antoine Zimmermann
Antoine Zimmermann

Reputation: 5515

It seems that one of the two lines below returns a null pointer:

subject = domainModel.getIndividual(bootbase + "Frame" + frameNum);                     
property = domainModel.getOntProperty(bootbase + "hasDuration");

Verify that you look for an existing URI.

Upvotes: 2

Related Questions