這是一個示例類我不知道爲什麼本網站服務無法正常工作
public class NewClass {
public String hello1(String txt) {
String a = "Hello " + txt + " !";
return a;
}
}
,這是一個簡單的Web服務
@WebService(serviceName = "NewWebService2")
public class NewWebService2 {
private NewClass newess;
/**
* This is a sample web service operation
*/
@WebMethod(operationName = "hello")
public String hello(@WebParam(name = "name") String txt) {
return "Hello " + txt + " !";
}
@WebMethod(operationName = "hello11")
public String hello11(@WebParam(name = "name") String txt) {
String ess=newess.hello1(txt);
return ess;
}
}
第一種方法hello
工程完全,但第二方法hello11
不起作用。我不明白這個問題。服務器顯示此消息:
SEVERE: java.lang.NullPointerException
at newpackage.NewWebService2.hello11(NewWebService2.java:31)
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:601)
at org.glassfish.webservices.InstanceResolverImpl$1.invoke(InstanceResolverImpl.java:143)
at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:149)
at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:94)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:961)
.
.
.
請我需要了解此問題以及如何解決它。
'newess'爲'null'。用newess = new NewClass()初始化它'' – jlordo