The error messages generated [ITALICS] G:\JavaCertification\SCJP\SCJPExamGuide\PaulShanghara\RobotManager.java:16: non-static variable this cannot be referenced from a static context robot = new Robot(); ^ G:\JavaCertification\SCJP\SCJPExamGuide\PaulShanghara\RobotManager.java:17: cannot find symbol symbol : method setName(java.lang.String) location: class RobotManager robot = setName(args); ^ 2 errors
Tool completed with exit code 1
[/ITALICS] [ DESCRIPTION ] The error messages generated express about robot variable not defined within a non static context But I have defined it inside the main method.[I]This code is from chapter1 of the SCJP study guide of Paul Shanghara.
There are two completely separate errors here. The first one happens because your "Robot" class is nested inside your RobotManager class (pay close attention to your opening and closing braces to see this.) Move class Robot entirely outside of RobotManager's enclosing braces to fix the problem.
The second error is happening because your "main" method is calling a setName() method as if it were a member of RobotManager, but it's not. To call setName() from RobotManager, there must be an instance of class Robot, and you must use the "dot" operator to call the method on that instance -- i.e.,
Finally, note that the argument to setName() is supposed to be a single String, not an array.