简体   繁体   中英

java.lang.InstantiationError while running sparql query in jena

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.

You have a mix of versions on the classpath.

The information you link to is correct - BindingMap became an interface so if you see java.lang.InstantiationError it means the calling code is from an earlier version of ARQ.

Check you don't have more than one copy of Jena code on the classpath, and there are not copies in endorsed directories of the JVM.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM