Announcement Announcement Module
Collapse
No announcement yet.
Bean problem in Simplest Sample Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Andor
    started a topic Bean problem in Simplest Sample

    Bean problem in Simplest Sample

    Hi, i'm experiencing a problem in the SimplestSample app http://forum.springframework.org/showthread.php?t=17405.

    A NullPointerException is thrown.
    Code:
    Exception in thread "main" java.lang.IllegalStateException: Application start thrown an exception: null
    	at org.springframework.richclient.application.ApplicationLauncher.launchMyRichClient(ApplicationLauncher.java:316)
    	at org.springframework.richclient.application.ApplicationLauncher.<init>(ApplicationLauncher.java:159)
    	at org.springframework.richclient.application.ApplicationLauncher.<init>(ApplicationLauncher.java:127)
    	at rcp.app.Main.main(Main.java:11)
    Caused by: java.lang.NullPointerException
    	at org.springframework.richclient.application.support.AbstractApplicationPage.showView(AbstractApplicationPage.java:301)
    	at org.springframework.richclient.application.support.AbstractApplicationPage.showView(AbstractApplicationPage.java:297)
    	at org.springframework.richclient.application.support.DefaultApplicationPage.addView(DefaultApplicationPage.java:47)
    	at org.springframework.richclient.application.support.SingleViewPageDescriptor.buildInitialLayout(SingleViewPageDescriptor.java:59)
    	at org.springframework.richclient.application.support.DefaultApplicationPage.createControl(DefaultApplicationPage.java:85)
    	at org.springframework.richclient.factory.AbstractControlFactory.getControl(AbstractControlFactory.java:83)
    	at org.springframework.richclient.application.support.DefaultApplicationWindow.setActivePage(DefaultApplicationWindow.java:47)
    	at org.springframework.richclient.application.support.AbstractApplicationWindow.showPage(AbstractApplicationWindow.java:192)
    	at org.springframework.richclient.application.support.AbstractApplicationWindow.showPage(AbstractApplicationWindow.java:158)
    	at org.springframework.richclient.application.Application.openWindow(Application.java:170)
    	at org.springframework.richclient.application.Application.start(Application.java:244)
    	at org.springframework.richclient.application.ApplicationLauncher$1.run(ApplicationLauncher.java:307)
    	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
    	at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
    	at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
    The application context I'm using is here:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
            "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    
      
      <bean id="application" class="org.springframework.richclient.application.Application">
        <constructor-arg index="0" ref="applicationDescriptor" />
        <constructor-arg index="1" ref="rcpAdvisor" />
      </bean>
    
      <bean id="rcpAdvisor" class="rcp.app.ApplicationAdvisor">
        <property name="windowCommandBarDefinitions">
          <value>/rcp/ctx/RCP-CommandsContext.xml</value>
        </property>
        <property name="startingPageId">
          <value>mainView</value>
        </property>
      </bean>
      
      <bean id="applicationDescriptor"
        class="org.springframework.richclient.application.support.DefaultApplicationDescriptor">
        <property name="version" value="1.0" />
        <property name="buildId" value="20060408-001" />
      </bean>
    
    
      <bean id="mainView" class="org.springframework.richclient.application.support.DefaultViewDescriptor">
        <property name="viewClass" value="rcp.gui.MainView"/>
      </bean>
    
      
      <bean id="imageResourcesFactory"
        class="org.springframework.context.support.ResourceMapFactoryBean">
        <property name="locations">
          <list>
            <value>classpath:/rcp/ctx/images.properties</value>
          </list>
        </property>
        <property name="resourceBasePath">
          <value>/rcp/images/</value>
        </property>
      </bean>
      
      <bean id="imageSource"
        class="org.springframework.richclient.image.DefaultImageSource">
        <constructor-arg index="0">
          <ref bean="imageResourcesFactory"/>
        </constructor-arg>
      </bean>
    
      <bean id="messageSource"
        class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basenames">
          <list>
            <value>rcp.ctx.messages.properties</value>
          </list>
        </property>
      </bean>
    </beans>
    The rest of the application is completely same as the SimplestSample (except for paths etc.).
    The app compiles, runs, shows the splashscreen but then it crashes, saying the above. I did a little tracing and noticed, that
    Code:
    return (ViewDescriptor) getApplicationContext().getBean(viewName, ViewDescriptor.class);
    in class BeanFactoryViewDescriptorRegistry, line 65 a NoSuchBeanDefinitionException is thrown, saying there is no 'mainView' bean definition in the context. The GenericContext variable in this time really doesn't seem to be properly initialized (all attributes in beanFactory are empty or null). Another look in the context(at earlier breakpoints) however shows that the context is loaded OK and contains the necessary bean 'mainView' (in the beanFactory attributes). The NoSuchBeanDefinition then causes the app to crash with the NPE.

  • Andor
    replied
    Seems there was a missing bean in the application context. Just adding the following lines fixes the NPE problem on application startup.

    Code:
        <bean id="serviceLocator" class="org.springframework.richclient.application.ApplicationServicesLocator">
        <property name="applicationServices" ref="applicationServices" />
      </bean>
    
      <bean id="applicationServices"
        class="org.springframework.richclient.application.support.DefaultApplicationServices" />

    Leave a comment:

Working...
X