• 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

Factory pattern problem

 
Ranch Hand
Posts: 106
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello i am trying example with factory pattern but i get an error. This is my code if anyone can help


the error is



and the code is








Why do i get such a message ?I have try the args[] array but it will not change.what can i do?
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Horche. Welcome to the Ranch!

Anyway, I assume Factory.java line 29 corresponds to line 12 in that listing? In that case, the problem is that the argument array doesn't have two entries. Maybe you should print out the array to check what it does actually contain. How are you executing the program?
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Horche Gratsias wrote:
Why do i get such a message ?I have try the args[] array but it will not change.what can i do?


String[] args is equivalent to String args[].
As Matthew pointed out the possible erroneous line, I think you are using an IDE to run the program and you need to setup the IDE to accept command line arguments.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes as mentioned above how the parameters passed to the program, look into that will make more clear .
 
Georgios Chatziefstratiou
Ranch Hand
Posts: 106
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might want to take a look at http://www.oodesign.com/factory-pattern.html to pick up some tips on a better implementation. As you'll see, your current implementation is what the article calls a "noob implementation" and violates what is called the "Open-Closed Principle" of object-oriented design.
reply
    Bookmark Topic Watch Topic
  • New Topic