Announcement Announcement Module
Collapse
No announcement yet.
XmlBeanFactory and NullPointerException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • XmlBeanFactory and NullPointerException

    Hi,
    I'm pretty new with Spring, and I'm trying to start with my very first example but I can't get it working, my code is the following in the main method:

    Code:
    XmlBeanFactory factory = new XmlBeanFactory(new InputStreamResource(new FileInputStream("src/prueba/beans.xml")));
    And my beans.xml, placed in the same package is the following:

    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="pruebaBean" class="prueba/PruebaBean" />
    </beans>
    If you need my PruebaBean code too please tell me, but it's pretty simple...
    When I try to run this code I obtain the following (running in Eclipse):

    Code:
    Exception in thread "main" java.lang.ExceptionInInitializerError
    	at prueba.PruebaApp.main(PruebaApp.java:28)
    Caused by: java.lang.NullPointerException
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.<clinit>(DefaultListableBeanFactory.java:104)
    	... 1 more
    Please I need an answer because I've tryied almost everything!!! thanks in advance!

  • #2
    I suggest a basic java tutorial.... the class should be prueba.PruebaBean and not with a /...

    Comment


    • #3
      yes of course, I copied it wrongly, but that doens't solve the problem at all...

      Comment


      • #4
        Is the class "PruebaBean" in the package prueba and is it compiled while running the app?

        Comment


        • #5
          Take a look at http://static.springsource.org/sprin...l#beans-basics

          Comment


          • #6
            Originally posted by parvinder View Post
            parvinder: Thanks!
            I replaced my code with the following:

            Code:
            ApplicationContext ctx = new FileSystemXmlApplicationContext("src/com/prueba/beans.xml");
            And it works like a charm!

            Comment

            Working...
            X