![](/img/trans.png)
[英]Validation error: “No validator could be found for type: java.lang.Integer”
[英]Jena Sparql Error java.lang.Integer
我有以下代碼:
RestClient client = new RestClient("http://localhost:8080/scheduler.core/rest/services/discoverSensors");
client.AddParam("userID", "keith@acrosslimits.com");
client.AddParam("longitude", "4.3512725830078125");
client.AddParam("latitude", "50.84761359783461");
client.AddParam("radius", "15.0");
client.AddHeader("accept", "application/xml");
try {
client.Execute(RestClient.RequestMethod.GET);
} catch (Exception e) {
e.printStackTrace();
}
String response = client.getResponse();
//System.out.println(response);
DocumentBuilder db = null;
try {
db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
System.out.println("error");
}
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(response));
Document doc = db.parse(is);
NodeList nodes = doc.getElementsByTagName("SensorType");
// Getting the id of the sensor
for(int x=0,size= nodes.getLength(); x<size; x++) {
String resourceID = nodes.item(x).getAttributes().getNamedItem("id").getNodeValue();
String sparqlQueryString = "select ?sensor ?lat ?lng "+
"from <http://lsm.deri.ie/OpenIoT/demo/sensormeta#> " +
"where{?sensor <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.oclc.org/NET/ssnx/ssn#Sensor>."+
"?sensor <http://lsm.deri.ie/ont/lsm.owl#hasSensorType> <http://lsm.deri.ie/resource/8a8291b73215690e013215a4c0d00f17>."+
"?sensor <http://www.loa-cnr.it/ontologies/DUL.owl#hasLocation> ?location."+
"?location <http://www.w3.org/2003/01/geo/wgs84_pos#lat> ?lat."+
"?location <http://www.w3.org/2003/01/geo/wgs84_pos#long> ?lng."+
"}limit 100";
System.out.println(resourceID);
System.out.println(sparqlQueryString);
Query query = QueryFactory.create(sparqlQueryString);
ARQ.getContext().setTrue(ARQ.useSAX);
System.out.println("1");
QueryExecution qexec = QueryExecutionFactory.sparqlService("http://lsm.deri.ie/sparql", query);
System.out.println("2");
//Retrieving the SPARQL Query results
ResultSet results = qexec.execSelect();
System.out.println("3");
//Iterating over the SPARQL Query results
while (results.hasNext()) {
QuerySolution soln = results.nextSolution();
System.out.println("4");
String SensorID = soln.get("?sensor").toString();
String lat = soln.get("?lat").toString();
String lon = soln.get("?lng").toString();
System.out.println(SensorID);
System.out.println(lat);
System.out.println(lon);
}
qexec.close();
}
}
我面臨的問題是,當我執行查詢時,正在顯示錯誤。 程序終止的行是2到3之間的行。顯示的錯誤是:
Exception in thread "main" java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
at org.apache.http.params.AbstractHttpParams.getIntParameter(AbstractHttpParams.java:70)
at org.apache.http.client.params.HttpClientParamConfig.getRequestConfig(HttpClientParamConfig.java:54)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:806)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
at org.apache.http.impl.client.DecompressingHttpClient.execute(DecompressingHttpClient.java:158)
at org.apache.http.impl.client.DecompressingHttpClient.execute(DecompressingHttpClient.java:139)
at org.apache.jena.riot.web.HttpOp.exec(HttpOp.java:1011)
at org.apache.jena.riot.web.HttpOp.execHttpGet(HttpOp.java:291)
at org.apache.jena.riot.web.HttpOp.execHttpGet(HttpOp.java:353)
at com.hp.hpl.jena.sparql.engine.http.HttpQuery.execGet(HttpQuery.java:326)
at com.hp.hpl.jena.sparql.engine.http.HttpQuery.exec(HttpQuery.java:276)
at com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP.execSelect(QueryEngineHTTP.java:346)
at ExecuteRestClient.main(ExecuteRestClient.java:114)
這是因為緯度和經度可變嗎? 我正在使用耶拿2.11。
@ZaoTaoBao在評論中指出的可能是您問題的根源-https: //github.com/pyvandenbussche/sparqles/issues/9
ARQ當前未使用Apache HTTP Client的最新版本,但是您的應用程序/類路徑中有某些內容,因此(從ARQ的角度來看)裝入了錯誤的類。 因此,當ARQ嘗試使用HttpClient API時,它期望最終會調用不再具有相同類型簽名的新API中的方法,並且您會收到ClassCastException
因此,這歸結為Java /應用程序特定的環境問題。
您需要檢查您的類路徑和/或依賴項層次結構,以了解使用Apache HttpClient的其他問題,並通過不使用比ARQ使用的版本新的版本來解決版本沖突。
mvn dependency:tree
是您在maven項目上進行調查的朋友,然后您可以使用依賴項排除來刪除較新的版本。 否則,您將需要使用IDE或構建系統提供的任何依賴項/類路徑管理支持來對此進行調查。
但是,如果您要混合使用需要多個版本的HttpClient的庫,那么這樣做只會破壞其他功能。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.