Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

On the quest for learning Spring, but need some help  RSS feed

 
Shashank Gokhale
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ive been following a tutorial on youtube and Im upto the point where we start using autowire.  But the program throws a nullpointerexception and the member variables dont get the proper values.  Im including the code so please let me know whats going on

This is the main program "Drawing.java"


My triangle classs "Triangle.java"


The Point class "Point.java"


and finally the xml file "Spring1.xml"


If I remove the autowire tag and include the property statements, then the application works, but if add in the autowire and delete the property statements, then the application gives a null pointer exception in Triangle class at line 54 (where it is supposed to prints the coordinates of point A" and also in the Drawing class at line 11 where the draw method is called.  Whats going on, why is it not working?
 
somashaker goud
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Everything looks fine with your code ,can you re-arrange your code like below and give a try

from




to

 
Shashank Gokhale
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it to work actually.  The problem was, and I dont know why, that I was naming my points A,B,C,D, and I named them as such in the xml file.  The issue was that Eclipse, when generating the getter and setter methods, especially the setter method was passing in lowercase d even though I had used D when declaring the Point D property.  And because the objects are case sensitive, I was getting the null pointer exception
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!