2

我有一个 android android 应用程序,我通过将变量传递给 servlet 来更新产品表。它更新了表格,但问题正在响应 android。在 servlet 中,当我试图将响应传回给 android 时,我得到了一个 nullpointerexception。似乎无法理解为什么我会得到这个,请帮助:)

     else if (option.equalsIgnoreCase(("addProduct"))) {

            //update code runs here and it is successfull

            if(optionmobile.equalsIgnoreCase("mobileaddproduct")){

                if(merchID != null){

                response.setContentType("text/html");
                ObjectOutputStream oos = new ObjectOutputStream(response.getOutputStream());
                oos.writeObject("executed");                        
                oos.flush();
                oos.close();       
               //if the merch != null; how do you stop the program here!
            }else{

                response.setContentType("text/html");
                ObjectOutputStream oos = new ObjectOutputStream(response.getOutputStream());
                oos.writeObject("faliedToUpload");                    
                oos.flush();
                oos.close();

            }

        }else{                   
            session.setAttribute("testing", u);
            address = "test.jsp";
            }
            //my guess it breaks here after it runs the first condition.
            RequestDispatcher dispatcher = request.getRequestDispatcher(address);
            dispatcher.forward(request, response);       

        }

这是一个 Java Web 应用程序,所以这就是为什么我有 if(optionmobile.equalsIgnoreCase("mobileaddproduct")){ 以便知道请求来自移动设备!

WARNING: StandardWrapperValve[MerchantController]: PWC1406: Servlet.service() for     servlet MerchantController threw exception
java.lang.NullPointerException
    at com.gobetween.merchant.MerchantController.processRequest(MerchantController.java:337)
at com.gobetween.merchant.MerchantController.doPost(MerchantController.java:374)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:232)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
4

0 回答 0