你能帮我解决下面这个问题。我在一台tomcat服务器上运行triplestore,并在另一台tomcat7服务器上运行应用程序以访问triplestore。第一次,应用程序成功运行,但是如果我重新启动应用程序而不是三元组导致nullpointer问题。
以下是在triplestore服务器上导致的异常
SEVERE: Servlet.service() for servlet [ServletAdaptor] in context with path [/triplestore] threw exception [java.lang.NullPointerException] with root cause
java.lang.NullPointerException
at com.hp.hpl.jena.sparql.util.NodeUtils$1.accept(NodeUtils.java:
at com.hp.hpl.jena.sparql.util.NodeUtils$1.accept(NodeUtils.java:91)
at com.hp.hpl.jena.util.iterator.MapFilterIterator.hasNext(MapFilterIterator.java:55)
at au.com.triplestore.core.impl.TripleStoreImpl.saveDataset(TripleStoreImpl.java:224)
at au.com.triplestore.web.TripleStoreRs.saveData(TripleStoreRs.java:323)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:151)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:171)
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:152)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:104)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:402)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:349)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:106)
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:259)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:318)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:236)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1010)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:373)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:382)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:345)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:220)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org .apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2441)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2430)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
以下是失败的代码(line is - while(listOfSavedNames.hasNext()){)
public Boolean saveDataset(Model model, String baseUri, Boolean isSave, String reasonerName) {
dataset.begin(ReadWrite.WRITE);
Boolean alreadySaved = false;
InfModel infModel = null;
if (baseUri == null) {
baseUri = model.getNsPrefixURI("ex");
}
Iterator<String> listOfSavedNames = dataset.listNames();
while (listOfSavedNames.hasNext()) {
if (baseUri.equals(listOfSavedNames.next())) {
alreadySaved = true;
break;
}
}
if (isSave) {
if (alreadySaved) {
Model defaultModel = dataset.getDefaultModel();
Model namedModel = dataset.getNamedModel(baseUri);
dataset.removeNamedModel(baseUri);
defaultModel.add(infModel);
namedModel.add(infModel);
//Add new model
dataset.addNamedModel(baseUri, namedModel);
} else {
Model defaultModel = dataset.getDefaultModel();
defaultModel.add(infModel);
dataset.addNamedModel(baseUri, infModel);
}
} else {
Model defaultModel = dataset.getDefaultModel();
Model namedModel = dataset.getNamedModel(baseUri);
dataset.removeNamedModel(baseUri);
defaultModel.add(infModel);
namedModel.add(infModel);
//Add new model
dataset.addNamedModel(baseUri, namedModel);
}
dataset.commit();
TDB.sync(dataset);
dataset.end();
schemaDataset.end();
return true;
}