将文字类型添加到模型中

时间:2010-07-11 16:29:48

标签: jsp jena

我尝试将数据类型属性值添加到我的模型中..工作正常..当我这样写时:

Literal link = model.createTypedLiteral("www.google.lk", XSDDatatype.XSDstring);
Statement value = model.createStatement(ind, pro, link);
model.add(value);

当我把它作为论据传递时:

Literal link = model.createTypedLiteral(onto.getlink(), XSDDatatype.XSDstring);

会出错:

org.apache.jasper.JasperException: Exception in JSP: /Onto web.jsp:54

51:       OntClass cul = model.getOntClass("http://www.owl-ontologies.com/Ontology1275995702.owl#srilanka");
52:    Individual ind = model.createIndividual("http://www.owl-ontologies.com/Ontology1275995702.owl#"+ onto.getIndividualname(),cul);
53:   
54:    Literal link = model.createTypedLiteral(onto.getLink(), XSDDatatype.XSDstring);
55:    Statement value = model.createStatement(ind, pro, link);
56:    model.add(value);
57:      


Stacktrace:
 org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:321)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:257)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:729)


root cause 

java.lang.NullPointerException
 com.hp.hpl.jena.graph.impl.LiteralLabelImpl.getDefaultHashcode(LiteralLabelImpl.java:429)
 com.hp.hpl.jena.datatypes.BaseDatatype.getHashCode(BaseDatatype.java:142)
 com.hp.hpl.jena.graph.impl.LiteralLabelImpl.hashCode(LiteralLabelImpl.java:419)
 com.hp.hpl.jena.graph.NodeCache.get(NodeCache.java:64)
 com.hp.hpl.jena.graph.Node.create(Node.java:285)
 com.hp.hpl.jena.graph.Node.createLiteral(Node.java:54)
 com.hp.hpl.jena.graph.Node.createLiteral(Node.java:91)
 com.hp.hpl.jena.rdf.model.impl.ModelCom.createTypedLiteral(ModelCom.java:545)
 org.apache.jsp.Onto_0020web_jsp._jspService(Onto_0020web_jsp.java:124)
 org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:321)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:257)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

可以帮助我解决这个问题......

感谢

1 个答案:

答案 0 :(得分:0)

可能onto.getlink()返回null?不允许将null作为Model.createTypedLiteral(value, type)的第一个参数传递。