View Single Post
  #6   Spotlight this post!  
Unread 16-01-2014, 07:51
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,725
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: CANNotInitializedException

Quote:
Originally Posted by arithehun View Post
Also, you cannot define a jaguar inside of a code block (in this case, your "try" block, and then use it anywhere outside of the block. Outside of any method, but inside your class, type (you may have already done this):

Code:
CANJaguar armMotor;
Then, change your code that you displayed to this:
(Basically remove the CANJaguar variable marker):

Code:
public void robotInit(){
     try {
          armMotor = new CANJaguar (4,       CANJaguar.ControlMode.kPosition);
     } catch (CANTimeoutException ex){
          ex.printStackTrace();
}
Essentially, what is happening is that you're not initializing your global CANJaguar variable. How Java works is that it allows global and local variables of the same name. So the Jaguar that you're initializing isn't the same one that you're using at line 70. You made a new Jaguar also called "armMotor" and initialized that one. Because it had a conflicting name, Java resolved this by "hiding" the global variable from that function. The armMotor inside robotInit() was discarded after robotInit ended. The other armMotor that you defined elsewhere was never touched. By removing the CANJaguar reference, you're not creating a new variable anymore but instead initializing the existing global one, which is what you intended on doing.
This would actually cause a compilation error, not a runtime error as the jaguar object would be out of scope when you tried to use it.
Reply With Quote