• Post Reply Bookmark Topic Watch Topic
  • New Topic

i got this error Cannot make a static reference to the non-static method?  RSS feed

 
karthik ekantha
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in eclispse itself some error display :




Cannot make a static reference to the non-static method retrieveProduct(ProductDetailsDTO) from the type ProductDetailsService









the interface : ProductDetailsService







 
dennis deems
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On lines 22/23 of your action class, you are making a static method call on the service interface. That doesn't work; you must call against an instance.
 
Randall Twede
Ranch Hand
Posts: 4696
8
Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in other word write a line like this
ProductDetailsDTO productDetailsDTO = new ProductDetailsDTO();
for ProductDetailsService
 
dennis deems
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Randall Twede wrote:in other word write a line like this
ProductDetailsDTO productDetailsDTO = new ProductDetailsDTO();
for ProductDetailsService


Well, sort of. I don't know the specifics of Struts, but typically service implementations are instantiated once, externally to the classes that use them, and are passed into constructors or autowired or whatever. The Action class shouldn't know that it has an instance of ProductDetailsServiceImpl; only that it has an instance of some class that implements the ProductDetailsService interface. If we let the Action class instantiate the service then that instantiation would happen every time the user clicked that button (or whatever it was), and most likely we don't want that either.
 
karthik ekantha
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what ill change
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!