Results 1 to 6 of 6

Thread: XmlBeanFactory and NullPointerException

  1. #1
    Join Date
    May 2010
    Posts
    14

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    I suggest a basic java tutorial.... the class should be prueba.PruebaBean and not with a /...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    May 2010
    Posts
    14

    Default

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

  4. #4
    Join Date
    Oct 2008
    Posts
    5

    Default

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

  5. #5
    Join Date
    Jun 2009
    Posts
    7

  6. #6
    Join Date
    May 2010
    Posts
    14

    Default

    Quote 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!

Tags for this Thread

Posting Permissions

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