• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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







 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what ill change
reply
    Bookmark Topic Watch Topic
  • New Topic