Go to Post Above all, have fun and, if you need help, ask for it... Your inspectors will be glad to help or try to arrange for another team to help you. This should not be a traumatic experience! - Mike Betts [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 21-03-2015, 14:49
L1TH1UM L1TH1UM is offline
Registered User
FRC #4334
Team Role: Programmer
 
Join Date: Mar 2015
Rookie Year: 2015
Location: Calgary, AB
Posts: 4
L1TH1UM is an unknown quantity at this point
Preferences table Null Pointer Exception

Hello,

We are having some issues using the preferences table utility on SmartDashboard. We are supposed to be getting a table from which we can edit robot preferences such as potentiometer setpoints and encoder setpoints.

However, when we run the code it throws a Null Pointer Exception because we declared the preferences varable (Preferences prefs but we didn't create and object and we are trying to use an operator (prefs.getDouble). Using "prefs = new Preferences();" does not work, and there's nothing on the wpilibj documentation that tells us how to fix this (create an object for preferences).

Here's the page we're referencing: https://wpilib.screenstepslive.com/s...smartdashboard

Our code is almost exactly the same as that just minor differences such as names and values. We are programming in Java.

Any help would be appreciated, thanks.
  #2   Spotlight this post!  
Unread 21-03-2015, 15:27
RufflesRidge RufflesRidge is offline
Registered User
no team
 
Join Date: Jan 2012
Location: USA
Posts: 990
RufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant future
Re: Preferences table Null Pointer Exception

The sample on that page seems to be missing a line:

prefs = Preferences.getInstance();
  #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: 543
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.
  #4   Spotlight this post!  
Unread 22-03-2015, 00:05
L1TH1UM L1TH1UM is offline
Registered User
FRC #4334
Team Role: Programmer
 
Join Date: Mar 2015
Rookie Year: 2015
Location: Calgary, AB
Posts: 4
L1TH1UM is an unknown quantity at this point
Re: Preferences table Null Pointer Exception

Thank you, I appreciate it. This fixed our problem.
  #5   Spotlight this post!  
Unread 22-03-2015, 10:57
MrRoboSteve MrRoboSteve is offline
Mentor
AKA: Steve Peterson
FRC #3081 (Kennedy RoboEagles)
Team Role: Mentor
 
Join Date: Mar 2012
Rookie Year: 2011
Location: Bloomington, MN
Posts: 581
MrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond repute
Re: Preferences table Null Pointer Exception

If you didn't do so already, please use the form on the page to report the error.
__________________
2016-17 events: 10000 Lakes Regional, Northern Lights Regional, FTC Burnsville Qualifying Tournament

2011 - present · FRC 3081 Kennedy RoboEagles mentor
2013 - present · event volunteer at 10000 Lakes Regional, Northern Lights Regional, North Star Regional, Lake Superior Regional, Minnesota State Tournament, PNW District 4 Glacier Peak, MN FTC, CMP
http://twitter.com/MrRoboSteve · www.linkedin.com/in/speterson
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 21:12.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi