• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able to understant object initialisation

 
Rahul Shivsharan
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Performer.java file


Juggler.java file


bean-prac-cfg.xml file


MainPractise04.java file, which i run ,


When i run the above file, the program runs fine and prints the sop in method perform();

but when i switch the xml file to new xml ie. bean-cfg.xml as follows,



and in MainPractise04.java, i change the path of called xml to bean-cfg.xml,
the perform() method is not called and i get Nullpointerexception, ie. obj is still null, thought the constructor sop of Juggler.java is called

why so ?

 
Rahul Shivsharan
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this the output, of the above code when i add bean-cfg.xml, and run MainPractise04.java from command prompt

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do me a favor and change the following.

Remove the try catch, no Idea why you need that there. It looks to me like you are trying things out, and the exception if thrown will be printed out anyway.

change

BeanFactory beanFactory = null;
beanFactory = new ClassPathXmlApplicationContext("bean-prac-cfg.xml");


so your code to start should look like this



That is much cleaner and what you should be doing using either Spring 2.5.6 or Spring 3.x

If you are trying to learn on an older version of Spring, I recommend using the latest.

Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as your error, what is different. I would say the other beans, so I would say one of the other beans has a problem. And I am going to guess, because the stack trace is too short there to show the real error. (By the, way read exceptions in Spring from bottom up, looking for the true root cause of the exception) I would say it is the initBean that is the cause of the problems.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic