View Single Post
  #5   Spotlight this post!  
Unread 17-01-2017, 22:14
SamCarlberg's Avatar
SamCarlberg SamCarlberg is offline
GRIP, WPILib. 2084 alum
FRC #2084
Team Role: Mentor
 
Join Date: Nov 2015
Rookie Year: 2009
Location: MA
Posts: 154
SamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to behold
Re: java.lang.NullPointerException

The issue is that when your subsystems are initialized, they get their values for all the RobotMap variables before those variables have been initialized. So you can either
  1. Initialize subsystems after calling RobotMap.init(); or
  2. Call RobotMap.init() in a static block in the RobotMap class; or
  3. Remove RobotMap.init() altogether and initialize its contents inline

What you're basically doing is:

Code:
Object a = null;
Object b = a; // set b to the _current_ value of a, which is null
a = new Object();

...

b.doSomething(); // null pointer exception!
__________________
WPILib
GRIP, RobotBuilder

Last edited by SamCarlberg : 17-01-2017 at 22:16.
Reply With Quote