0

これはサンプルクラスです

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は正確に機能しますが、2 番目の方法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)
    .
    .
    .

この問題とその解決方法を理解する必要があります。

4

2 に答える 2

0

NewClass newessを初期化します。newess 変数を初期化せずに newess.hello1() にアクセスしようとしています

于 2013-07-24T09:50:39.420 に答える