2

Dear Friends I m using Jena framework with RDF database model with virtuoso in my project. my jena version is jena-core2.7.2 and jena-arq-2.9.2

Here is the my code which is giving me error

public JsonArray getCountryAutoSuggestData()
{
    JsonArray countryArray = new JsonArray();
    Model model = DataModel.getModel();
    String mystr = " PREFIX plcontologyurl:<http://www.plcontology.com/#> "
            + " PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
            + "select ?cn"
            + " where "
            + " { "
            + " ?d plcontologyurl:Country_Name ?cn . "
            + "}";
    Query query = QueryFactory.create(mystr);
    QueryExecution qe = QueryExecutionFactory.create(query, model);
    QuerySolutionMap qMap = new QuerySolutionMap();
    qe.setInitialBinding(qMap);
    ResultSet rs = qe.execSelect();
    while(rs.hasNext())
    {
        qMap = (QuerySolutionMap)rs.next();
        countryArray.add(new JsonPrimitive(qMap.getLiteral("cn").getString()));
    }
    return countryArray;
}

Error is java.lang.InstantiationError: com.hp.hpl.jena.sparql.engine.binding.BindingMap at line while(rs.hasNext())

I tried looking for the problem and I found one relevant discussion

They are saying that now com.hp.hpl.jena.sparql.engine.binding.BindingMap is not a simple class now in this version but an interface now.

If it is like that then how to run sparql query in the current version. Please give an example based on the code i have shared. Thanks in advance.

4

1 回答 1

4

您在类路径上有多种版本。

您链接到的信息是正确的 - BindingMap 变成了一个接口,因此如果您看到 java.lang.InstantiationError,则表示调用代码来自 ARQ 的早期版本。

检查您在类路径上没有超过一份 Jena 代码副本,并且在 JVM 的认可目录中没有副本。

于 2012-08-20T11:26:43.317 回答