Announcement Announcement Module
Collapse
No announcement yet.
Nullpointer exception with IOC inheritance Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment

    Working...
    X