View Single Post
  #3   Spotlight this post!  
Unread 21-03-2015, 21:33
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: Preferences table Null Pointer Exception

Quote:
Originally Posted by RufflesRidge View Post
The sample on that page seems to be missing a line:

prefs = Preferences.getInstance();
You're right! Thats quite funny. Here's the actual code for reference

Code:
package org.usfirst.frc.team40.robot;

import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.Preferences;

public class Robot extends SampleRobot{

    Preferences prefs;
    double armUpPosition;
    double armDownPosition;
    public void robotInit(){
        prefs = Preferences.getInstance();
        armUpPosition = prefs.getDouble("ArmUpPosition", 1.0);
        armDownPosition = prefs.getDouble("ArmDownPosition", 4.0);
    }
}
On a side note, to follow NetworkTable conventions the method name should be "getNumber" but that is trivial.