View Single Post
  #2   Spotlight this post!  
Unread 16-02-2013, 22:49
arithehun arithehun is offline
Registered User
AKA: Ari Falkner
FRC #3024
Team Role: Programmer
 
Join Date: Feb 2011
Rookie Year: 2011
Location: Ashland, Oregon
Posts: 27
arithehun is an unknown quantity at this point
Re: CANNotInitializedException

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.
Reply With Quote