8 Replies Latest reply: Mar 19, 2009 8:25 PM by YE RSS

    Jdeveloper 11g: java.lang.NullPointerException

    YE
      I use Jdev 11 to create a table and write following code to the backbean. But I get errors of java.lang.NullPointerException

      I copy most of code from Jdev 10.

      -------------------code snippet------------------------------------------
      import org.apache.myfaces.trinidad.component.core.input.CoreInputText;

      private CoreInputText inputText1, inputText2, inputText3, inputText4;


      public void setInputText1(CoreInputText inputText1) {
      this.inputText1 = inputText1;
      }

      public CoreInputText getInputText1() {
      return inputText1;
      }


      public void setInputText2(CoreInputText inputText2) {
      this.inputText2 = inputText2;
      }

      public CoreInputText getInputText2() {
      return inputText2;
      }

      public void setInputText3(CoreInputText inputText3) {
      this.inputText3 = inputText3;
      }

      public CoreInputText getInputText3() {
      return inputText3;
      }

      public void setInputText4(CoreInputText inputText4) {
      this.inputText4 = inputText4;
      }

      public CoreInputText getInputText4() {
      return inputText4;
      }


      public String commandButton1_action() {
      String s1="", s2="",s3="", s4="";

      int rwCount3 = getTable1().getRowCount();

      for (int i = 0; i < rwCount3; i++) {
      System.out.println("current row ="+i);

      s1=inputText1.getValue().toString(); // get error from here
      s2=inputText2.getValue().toString();
      s3=inputText3.getValue().toString();
      s4=inputText4.getValue().toString();


      System.out.println("s1="+s1);
      System.out.println("s2="+s2);
      System.out.println("s3="+s3);
      System.out.println("s4="+s4);
      }
      return null;
      }



      -------------------error message-----------------------------------------
      java.lang.NullPointerException
      javax.faces.el.EvaluationException: java.lang.NullPointerException
           at org.apache.myfaces.trinidad.component.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:51)
           at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
           at org.apache.myfaces.trinidad.component.UIXCommand.broadcast(UIXCommand.java:190)
           at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:458)
           at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:763)
           at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._invokeApplication(LifecycleImpl.java:640)
           at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:275)
           at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:175)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
           at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
           at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
           at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
           at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
           at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
           at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:181)
           at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
           at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:85)
           at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:279)
           at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._invokeDoFilter(TrinidadFilterImpl.java:239)
           at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:196)
           at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:139)
           at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
           at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
           at oracle.security.jps.wls.JpsWlsFilter.doFilter(JpsWlsFilter.java:102)
           at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:65)
           at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
           at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
           at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
           at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3496)
           at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
           at weblogic.security.service.SecurityManager.runAs(Unknown Source)
           at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
           at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
           at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
           at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
           at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
      Caused by: java.lang.NullPointerException
           at Application9.view.backing.A8p1.commandButton1_action(A8p1.java:121)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:597)
           at com.sun.el.parser.AstValue.invoke(AstValue.java:157)
           at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:283)
           at org.apache.myfaces.trinidad.component.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:46)
           ... 35 more
      <2009-3-17 上午11时05分11秒 CST> <Error> <HTTP> <BEA-101017> <[weblogic.servlet.internal.WebAppServletContext@1ec072b - appName: 'Application9', name: 'Application9-ViewController-context-root', context-path: '/Application9-ViewController-context-root', spec-version: '2.5', request: weblogic.servlet.internal.ServletRequestImpl@447d40[
      POST /Application9-ViewController-context-root/faces/a8p1.jspx?_adf.ctrl-state=1895461271_3 HTTP/1.1
      Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
      Referer: http://127.0.0.1:7101/Application9-ViewController-context-root/faces/a8p1.jspx?_adf.ctrl-state=1895461271_3
      Accept-Language: zh-cn
      Content-Type: application/x-www-form-urlencoded
      UA-CPU: x86
      Accept-Encoding: gzip, deflate
      User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)
      Content-Length: 860
      Connection: Keep-Alive
      Cache-Control: no-cache
      Cookie: oracle.uix=0^^GMT+8:00; JSESSIONID=4pyLJ1TdpYvV2R0hh1Llzv42zL7z6TtpjvJXxXlhGfg5kpr4Vdl6!874731228

      ]] Root cause of ServletException.
      javax.faces.el.EvaluationException: java.lang.NullPointerException
           at org.apache.myfaces.trinidad.component.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:51)
           at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
           at org.apache.myfaces.trinidad.component.UIXCommand.broadcast(UIXCommand.java:190)
           at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:458)
           at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:763)
           Truncated. see log file for complete stacktrace
      java.lang.NullPointerException
           at Application9.view.backing.A8p1.commandButton1_action(A8p1.java:121)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:597)
           Truncated. see log file for complete stacktrace
      >
        • 1. Re: Jdeveloper 11g: java.lang.NullPointerException
          676633
          Hi,
          wrote:user_7000029

          s1=inputText1.getValue().toString(); // get error from hereI am just taking a guess here. Either:
          1) inputText1 is null, or
          2) inputText1.getValue() is null.

          If #1, there may be some problem with your object binding to the backing bean. Make sure you binded the inputText to your backing bean *binding="#{backingbean. inputText1}"*.
          If #2, you left the inputText blank when you clicked the button. You can try using *(String)inputText1.getValue()* instead.

          Regards,
          Chan Kelwin
          • 2. Re: Jdeveloper 11g: java.lang.NullPointerException
            YE
            Hi Chan Kelwin,

            Thanks for your reply.

            The inputText1 is bind to #{row.bindings.Id.inputValue}. I try #2, but the NullPointerException error still appears.

            Originally the page and java files have not the name like inputText1 and get/set methods. I add the get/set method in the backbean.
            The richTable is bind to a database table entity. The richTable has a createinsert button and a delete button. The user can insert new rows and key in data, update data in rows, and delete rows.

            Therefore, I just want to get data from the table. If my above code cannot be used in Jdev11g, could you tell me other method to get values of a table?

            Thank you.
            • 3. Re: Jdeveloper 11g: java.lang.NullPointerException
              676633
              Hi,

              If you don't bind the inputText to the backingBean (inputText1 component), your inputText1 variable will always be null. If you are just trying to insert a new record using the createInsert/commit function, hopefully these few links will be of some help.

              http://andrejusb.blogspot.com/2006/12/creating-new-row-using-createinsert.html
              ADF Faces & BC: Difference between Create and CreateInsert.
              Re: Invoking CreateInsert from a managed bean

              You can remove the codes private CoreInputText inputText1, inputText2, inputText3, inputText4; and the other getter/setter methods, since you won't be using them.

              If you are trying to read the current selected row and get each columns, you can try using the selectionListener method in the table.

              Regards,
              Chan Kelwin
              • 4. Re: Jdeveloper 11g: java.lang.NullPointerException
                YE
                The reason why I add inputText1 to 4 and get/set method is that Jdeveloper 10 can create them automatically.
                But in Jdeveloper 11g, I cannot find them.
                I can write code and bind these fields to get/set method. It is not a big problem.
                But I need the values of all input fields of the table in the current page.
                • 5. Re: Jdeveloper 11g: java.lang.NullPointerException
                  676633
                  Hi,

                  You can try out the following codes. You won't need the binding, getter and setter methods in the backing bean.
                  ApplicationModule yourAM = getAppModule();
                  ViewObject vo = yourAM.findViewObject("YourViewObjectView1");
                  while (vo.hasNext()) {
                      Row row = vo.next();
                      System.out.println("Column1: " + row.getAttribute("Column1"));
                      System.out.println("Column2: " + row.getAttribute("Column2"));
                      System.out.println("Column3: " + row.getAttribute("Column3"));
                  }
                  http://database.in2p3.fr/doc/oracle/Oracle_Application_Server_10_Release_3/web.1013/b25947/bcquerying007.htm
                  http://database.in2p3.fr/doc/oracle/Oracle_Application_Server_10_Release_3/web.1013/b25947/bcvoeo008.htm

                  Regards,
                  Chan Kelwin
                  • 6. Re: Jdeveloper 11g: java.lang.NullPointerException
                    YE
                    Hi,
                    Thanks for your code sample. I try the following code. But I still get errors of NullPointerException.

                    System.out.println("11111111111");

                    //AppModuleImpl yourAM= new AppModuleImpl();
                    //ViewObject vo = yourAM.findViewObject("SzTableView1");

                    AppModuleDefImpl yourAM=new AppModuleDefImpl();
                    ViewObject vo = (ViewObject)yourAM.findViewObject("SzTableView1");

                    System.out.println("2222222222");

                    while (vo.hasNext()) {
                    System.out.println("333333333333");
                    Row row = vo.next();
                    System.out.println("Column1: " + row.getAttribute("Id"));
                    }
                    return null;


                    -------------error message-------------------------
                    11111111111
                    2222222222
                    2009-3-18 11:10:42 com.sun.faces.application.ActionListenerImpl processAction
                    java.lang.NullPointerException
                    javax.faces.el.EvaluationException: java.lang.NullPointerException
                         at org.apache.myfaces.trinidad.component.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:51)
                         at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
                         at org.apache.myfaces.trinidad.component.UIXCommand.broadcast(UIXCommand.java:190)
                         at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:458)
                         at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:763)
                    • 7. Re: Jdeveloper 11g: java.lang.NullPointerException
                      676633
                      Hi,

                      Did you checkout any of the links I posted? You cannot instantiate the AM like that. The getAppModule() method I posted can be something like below:
                      public ApplicationModule getAppModule() {
                          String amDef = "devguide.model.SRService";
                          String config = "SRServiceLocal";
                          return am = Configuration.createRootApplicationModule(amDef,config);
                      }
                      You will have to change amDef and config to point to your AM.

                      Regards,
                      Chan Kelwin
                      • 8. Re: Jdeveloper 11g: java.lang.NullPointerException
                        YE
                        Hi Chan Kelwin,

                        Thanks for your help and code snippet.

                        I solve this problem by adding an inputText graphic component into the jspx design page but outside the table.
                        Then, Jdeveloper 11 will automatically create the get/set method in the backing bean.
                        Then, I move the inputText field into the table column and bound with the value.
                        Now I can get the value of the inputText fields of the ADF table

                        Edited by: user_7000029 on Mar 20, 2009 9:25 AM