我有这段代码,但我不明白为什么会收到 NullPointerException:
public static ArrayList<String> retrieveObject(String istance,String property){
String sparqlQueryString= "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf- syntax-ns#> "+
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "+
"PREFIX dbpedia: <http://dbpedia.org/resource/> "+
"PREFIX o: <http://dbpedia.org/ontology/> "+
"PREFIX dbprop: <http://dbpedia.org/property/>"+
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>" +
"select ?c"+
"where {<"+istance+"> "+property+" ?c.}";
ArrayList<String> array = new ArrayList<String>();
Query query = QueryFactory.create(sparqlQueryString);
QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);
ResultSet res = qexec.execSelect();
for(; res.hasNext();) {
QuerySolution soln = res.nextSolution();
for(int i=0;i<query.getProjectVars().size();i++){
array.add(soln.get(query.getProjectVars().get(i).getVarName()).asResource().toString());
}
}
return array;
}
我以这种方式调用该方法:
System.out.println(retrieveObject("http://dbpedia.org/resource/Immanuel_Kant","o:deathPlace"));