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?
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.
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.