简体   繁体   English

在耶拿运行sparql查询时出现java.lang.InstantiationError

[英]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. 亲爱的朋友,我在项目中使用Jena框架和virtuoso以及RDF数据库模型。 my jena version is jena-core2.7.2 and jena-arq-2.9.2 我的jena版本是jena-core2.7.2和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()) 错误是java.lang.InstantiationError:com.hp.hpl.jena.sparql.engine.binding.BindingMap在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. 他们说现在com.hp.hpl.jena.sparql.engine.binding.BindingMap在此版本中现在不是一个简单的类,而是一个接口。

If it is like that then how to run sparql query in the current version. 如果是这样,那么如何在当前版本中运行sparql查询。 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. 您链接到的信息是正确的-BindingMap成为接口,因此,如果看到java.lang.InstantiationError,则表明调用代码来自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. 检查类路径上是否有多个Jena代码副本,并且JVM的认可目录中没有副本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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