Results 1 to 2 of 2

Thread: Nullpointer exception with IOC inheritance

Hybrid View

  1. #1

    Default Nullpointer exception with IOC inheritance

    I'm getting a nullpointer exception in the MenuController class when when the property rightFrame calls a function.

    MenuController extends AdminController which again extends BaseController and the property rightFrame is set in BaseController and overridden in AdminController through bean injection inapplicationContext.xml.

    Why am I getting a nullpointer exception? Can anyone help?

    applicationContext.xml
    Code:
    <bean id="baseController" class="controllers.BaseController">
        <property name="rightFrame" ref="defaultRightFrame" />
      </bean>
    
      <bean id="adminController" class="controllers.AdminController" parent="baseController">
        <property name="rightFrame" ref="adminRightFrame" />
      </bean>
    
      <bean id="defaultRightFrame" class="util.RightFrameImpl" />
      <bean id="adminRightFrame" class="util.AdminRightFrameImpl" />
    BaseController
    Code:
    public class BaseController {
      protected RightFrame rightFrame;
    
      public BaseController(){}
    
      public RightFrame getRightFrame() { return rightFrame; }
    
      public void setRightFrame(RightFrame rightFrame) {
        this.rightFrame = rightFrame;
      }
    }
    AdminController
    Code:
    public class AdminController extends BaseController {}

    MenuController
    Code:
    public class MenuController extends AdminController {
    
      @RequestMapping("/admin/viewMainMenu.do")
      public String viewAdminMenu(HttpServletRequest request, ModelMap model) {
    
        rightFrame.setTest("This is a test"); //rightFrame is NULL!!!!!!
    
        return "viewAdminMainMenu";
      }
    }
    Interface RightFrame
    Code:
    public interface RightFrame {
     public void setTest(String test);
    }
    AdminRightFrameImpl
    Code:
    public class AdminRightFrameImpl implements RightFrame{
      private String test;
    
      @Override
      public void setTest(String t){
        test = t;
      }
    }

  2. #2
    Join Date
    Dec 2010
    Location
    Singapore
    Posts
    284

    Default

    Is it a problem with the way you have configured the MenuController bean in your application context?

    BTW you have forgot to post the MenuController configuration
    Amila Domingo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •