Results 1 to 3 of 3

Thread: Null Pointer Exception - newbie

  1. #1
    Join Date
    Jul 2007
    Posts
    11

    Default Null Pointer Exception - newbie

    Hello everybody,

    I am currently learning spring ( version 2.0.3 ) and getting a null pointer exception.
    I have the following bean definitions in an application context:

    Code:
        
        <bean id="manager" class="business.Manager">
       
        <bean id="defaultController" class="controller.DefaultController">
            <property name="manager">
            	<ref bean="manager"/>
            </property>
        </bean>
    
        <bean id="firstController" class="controller.FirstController"/>
    The DefaultController class has the getter and setters for the manager.
    The FirstController class looks like :

    Code:
    public class FirstController extends DefaultControllor implements Controller {
    
    public ModelAndView handleRequest ( 
       HttpServletRequest request, 
       HttpServletResponse response) {
    
       Manager mgr = getManager();
       mgr.myMethod();  
    
    }
    }
    Now when I access the myMethod from Manager class, it throws a null pointer. Am quite sure am doing some stupid, any suggestions ?
    Shouldn't the applicationContext intialize the manager object from the super class ?

    thanks

  2. #2
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    You have actually two beans. One of type DefaultController with the manager set and one of class FirstController where the manager is not set.

    I guess you wish to use one bean as template for the other, which might be done like this:
    Code:
    <bean id="manager" class="business.Manager">
       
        <bean id="defaultController" abstract="true">
            <property name="manager">
            	<ref bean="manager"/>
            </property>
        </bean>
    
        <bean id="firstController" parent"defaultController" class="controller.FirstController"/>
    Now you have only one bean which derives attributes from its abstract parent.

  3. #3
    Join Date
    Jul 2007
    Posts
    11

    Default

    Andreas, thats exactly was my question.

    Thank you

Posting Permissions

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